About Question enthuware.ocpjp.v17.2.3791

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
theujior
Posts: 11
Joined: Fri Sep 09, 2022 8:41 am
Contact:

About Question enthuware.ocpjp.v17.2.3791

Post by theujior »

the question explains
date1.compare(date2) will return second date minus first date in seconds i.e. -14400, which, if converted to hours will be -1.

At first, maybe
date1.getOffset().compareTo(date2.getOffset()) will return second offset minus first offset in seconds i.e. -3600, which, if converted to hours will be -1.

API Document of ZoneOffset.compareTo explains

Returns:
the comparator value, negative if less, positive if greater


It is typical returns of Comparable.compareTo(, although zero is missing).
It does not be required to return the difference between offsets in seconds.
The actual return values depend on system class libraries, the implementation of the Date and Time API.
(Sorry for wrong expression on About Question enthuware.ocpjp.v17.2.3577)

Maybe, with the class libraries based on OpenJDK (although I don't know another),
ZoneOffset.compareTo would return the difference between offsets in seconds.
But it is wrong to conclude that ZoneOffset.compareTo returns the difference between offsets in seconds.
Returns happened to be implemented so, and might be changed to, for example -1,0,1.

And order of ZoneOffset should be explained.
API Document of ZoneOffset.compareTo explains

Compares this offset to another offset in descending order.
The offsets are compared in the order that they occur for the same time of day around the world. Thus, an offset of +10:00 comes before an offset of +09:00 and so on down to -18:00.


It is the reason why second offset minus first offset, not first minus second.

In addition, I think that compareTo should not be used for any purposes other than comparison.

This question should be modified or remaked, not explain "it would not be a good idea to rely upon it".

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v17.2.3791

Post by admin »

Thank you for your feedback. This will be updated asap.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests