Date and Time library for Ceylon language SDK.
This library is loosely modeled/inspired by the JodaTime/JSR-310 date/time library.
Packages | |
ceylon.time | “Main package for the Ceylon's Date and Time library. |
ceylon.time.base | Base classes and interfaces of the Date/Time library. |
ceylon.time.chronology | Package containing supported chronologies in ceylon.time library. |
ceylon.time.internal | |
ceylon.time.internal.math | |
ceylon.time.timezone |
“Main package for the Ceylon's Date and Time library.
Like in JodaTime and JSR-310, there is a machine timeline and a human timeline.
Machine timeline is represented by an Instant that is basically just an object wrapper around an Integer representing Unix time value. A value of an Instant uniquely identifies a particular instant of time without needing to take into account timezone information and contain no ambiguities associated with DST changeover times.
Human timeline is based mostly on Gregorian and ISO 8601 calendar systems and consists of the following principal data types:
Note: At the moment, timezone support and awareness is missing from the library, so all of the time and date types and conversions behave as though staying in UTC-0.
Attributes | |
systemTime | Source Code shared systemTime systemTime Gets a clock that obtains the current instant using the best available system clock. |
zero | Source Code shared Period zero A period of zero length |
Methods | |
date | Source Code Returns a date based on the specified year, month and day-ofMonth values |
dateTime | Source Code shared DateTime dateTime(Integer year, Integer|Month month, Integer date, Integer hour, Integer minutes, Integer seconds, Integer millis) Returns a date based on the specified year, month and day-of-month values |
fixedTime | Source Code Gets a clock that always returns the same instant in the UTC time-zone. |
now | Source Code Obtains the current instant from the system clock. |
time | Source Code shared Time time(Integer hours, Integer minutes, Integer seconds, Integer millis) Creates new instance of Time. |
today | Source Code Returns current date according to the provided system clock and time zone. |
Interfaces | |
Clock | Source Code shared Clock A clock providing access to the current instant, date and time using a time-zone. Instances of this class are used to find the current instant, which can be interpreted using the stored time-zone to find the current date and time. As such, a clock can be used instead of {@link System#currentTimeMillis()} and {@link TimeZone#getDefault()}. The primary purpose of this abstraction is to allow alternate clocks to be plugged in as and when required. Applications use an object to obtain the current time rather than a static method. This can simplify testing. Applications should avoid using the static methods on this class. Instead, they should pass a {@code Clock} into any method that requires it. A dependency injection framework is one way to achieve this: public class MyBean { private Clock clock; // dependency inject ... public void process(LocalDate eventDate) { if (eventDate.isBefore(LocalDate.now(clock)) { ... } } } This approach allows an alternate clock, such as {@link #fixed} to be used during testing. The {@code system} factory method provides clocks based on the best available system clock, such as {@code System.currentTimeMillis}. |
Date | Source Code shared Date An interface for date objects in the ISO-8601 calendar system. A date is often viewed as triple of year-month-day values. This interface also defines access to other date fields such as day-of-year, day-of-week and week-of-year. |
DateTime | Source Code shared DateTime An abstract moment in time (like 4pm, October 21. 2012). DateTime does not contain a time zone information, so You can not use it to record or schedule events. |
Time | Source Code shared Time Time of day like 6pm or 8.30am. This type contains only information about an abstract time of day without referencing any date or timezone. You use Time to specify something that has to occur on a specific time of day like “lunch hour starts at 1pm” or “shop opens at 10am”. |
Classes | |
Duration | Source Code shared Duration Duration specifies a discreet amount of milliseconds between two instances of time. |
Instant | Source Code shared Instant A specific instant of time on a continuous time-scale. An instant represents a single point in time irrespective of any time-zone offsets or geographical locations |
Period | Source Code shared Period An immutable period consisting of the ISO-8601 years, months, days, hours, minutes, seconds and milliseconds, such as '3 Months, 4 Days and 7 Hours'. A period is a human-scale description of an amount of time. |
systemTime | Source Code shared systemTime Gets a clock that obtains the current instant using the best available system clock. |