I'm currently implementing a custom time system in Java. The system uses only one unit called "tick", which equals to 3.6 seconds, and therefore 24000 tick equals to a full day.
After I started implementing the system by implementing the Temporal interface, I've found that it might be unnecessary to implement a full-fledged Temporal, but rather just implement a TemporalUnit and TemporalField.
According to the documentation of the Temporal interface:
When to implement
A class should implement this interface if it meets three criteria:
- it provides access to date/time/offset information, as per
TemporalAccessor- the set of fields are contiguous from the largest to the smallest
- the set of fields are complete, such that no other field is needed to define the valid range of values for the fields that are represented
Four examples make this clear:
LocalDateimplements this interface as it represents a set of fields that are contiguous from days to forever and require no external information to determine the validity of each date. It is therefore able to implement plus/minus correctly.LocalTimeimplements this interface as it represents a set of fields that are contiguous from nanos to within days and require no external information to determine validity. It is able to implement plus/minus correctly, by wrapping around the day.MonthDay, the combination of month-of-year and day-of-month, does not implement this interface. While the combination is contiguous, from days to months within years, the combination does not have sufficient information to define the valid range of values for day-of-month. As such, it is unable to implement plus/minus correctly.- The combination day-of-week and day-of-month ("Friday the 13th") should not implement this interface. It does not represent a contiguous set of fields, as days to weeks overlaps days to months.
Is my time system not meet the three criteria? If not, can I makes it fit the criteria by adding support of time-based ChronoUnit and ChronoField?