Source Code

Date and Time library for Ceylon language SDK.

This library is loosely modeled/inspired by the JodaTime/JSR-310 date/time library.

By: Diego Coronel, Roland Tepp
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.iso8601

This package contains parsers implementations for reading Date, Time, DateTime, TimeZone, and ZoneDateTime values from t…

ceylon.time.timezone
ceylon.time.timezone.model

All the models are intended to be unrelated of the database origin.

ceylon.time.timezone.parser.iana
Dependencies
ceylon.collection1.2.2

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

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

Human timeline is based mostly on Gregorian and ISO-8601 calendar systems and consists of the following principal data types:

  • Date – A date value without time component.
  • Time – A time of day vallue without date component.
  • DateTime – A particular time of a particular date.
  • ZoneDateTime – A particular moment of time identified by date, time of day and a time zone.

Note: At the moment, timezone is not fully supported, therefore current conversions can uses offsets provided by VMs and provides some features like timeZone object that allows parser and creation of fixed offsets.

By: Diego Coronel, Roland Tepp
Values
systemTimeSource Codeshared systemTime systemTime

Gets a clock that obtains the current instant using the best available system clock.

zeroSource Codeshared Period zero

A period of zero length.

Functions
dateSource Codeshared Date date(Integer year, Integer|Month month, Integer day)

Returns a date based on the specified year, month and day of month values.

dateTimeSource Codeshared DateTime dateTime(Integer year, Integer|Month month, Integer day, Integer hours = 0, Integer minutes = 0, Integer seconds = 0, Integer milliseconds = 0)

Returns a date based on the specified year, month and day of month values.

Parameters:
  • hours = 0
  • minutes = 0
  • seconds = 0
  • milliseconds = 0
fixedTimeSource Codeshared Clock fixedTime(Instant|Integer instant)

Gets a clock that always returns the same instant in the UTC time-zone.

nowSource Codeshared Instant now(Clock? clock = null)

Obtains the current instant from the system clock.

Parameters:
  • clock = null
offsetTimeSource Codeshared Clock offsetTime(Clock baseClock, Duration offset)

Returns an implementation of a clock that always returns a constant offset from the value of the provided clock.

timeSource Codeshared Time time(Integer hours, Integer minutes, Integer seconds = 0, Integer milliseconds = 0)

Creates new instance of Time.

Parameters:
  • hours

    Hours of the day (0..23).

  • minutes

    Minutes of the hour (0..59).

  • seconds = 0

    Seconds of the minute (0..59).

  • milliseconds = 0

    Milliseconds of the second (0..999).

todaySource Codeshared Date today(Clock clock = ..., TimeZone timeZone = ...)

Returns current date according to the provided system clock and time zone.

Parameters:
  • clock = systemTime
  • timeZone = tz.system
Interfaces
ClockSource Codeshared 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 system.milliseconds.

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 top level objects directly. Instead, they should pass a Clock into any method that requires it. A dependency injection framework is one way to achieve this.

This approach allows an alternate clock, such as fixedTime() to be used during testing.

The systemTime top level factory method offers clocks based on the best available system clock, such as system.milliseconds.

DateSource Codeshared 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.

DateTimeSource Codeshared 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.

TimeSource Codeshared 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
DateRangeSource Codeshared DateRange

Implementation of Range and allows easy iteration between Date types.

Provides all power of Iterable features and complements with:

  • Easy way to recover Period
  • Easy way to recover Duration
  • Recover the overlap between DateRange types
  • Recover the gap between DateRange types
  • Allows customized way to iterate as navigate between values by UnitOfDate cases
DateTimeRangeSource Codeshared DateTimeRange

Implementation of Range and allows easy iteration between DateTime types.

Provides all power of Iterable features and complements with:

DurationSource Codeshared Duration

Duration specifies a discreet amount of milliseconds between two instances of time.

InstantSource Codeshared 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.

PeriodSource Codeshared 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.

TimeRangeSource Codeshared TimeRange

Implementation of Range and allows easy iteration between Time types.

Provides all power of Iterable features and complements with:

  • Easy way to recover Period
  • Easy way to recover Duration
  • Recover the overlap between TimeRange types
  • Recover the gap between TimeRange types
  • Allows customized way to iterate as navigate between values by UnitOfTime cases
systemTimeSource Codeshared systemTime

Gets a clock that obtains the current instant using the best available system clock.