ballerina/time

2.0.0-beta.2

Overview

This module provides a set of APIs that have the capabilities to generate and manipulate UTC and localized time.

In cloud computing, the most essential type of time is UTC. Coordinated Universal Time (UTC) is the primary time standard on which the world agreed. UTC is independent of daylight saving time and provides a unique time value for the entire world. The definition of UTC started from the epoc 1970-01-01T00:00:00Z. Initially, humans divided a day into 86400 seconds. However, the Earth rotation does not adhere to this time duration as the Earth is slowing down and the day is getting longer. As a result, a solar day in 2012 is longer than 86400 SI seconds. To correct this incompatibility, additional seconds have been added to the UTC scale, which is known as leap-seconds.

The focus of this module is to give the most precise UTC with nanoseconds precision and also handle some complex use cases such as leap seconds and daylight time-saving.

UTC Time

The time:Utc is the tuple representation of the UTC. The UTC represents the number of seconds from a specified epoch. Here, the epoch is the UNIX epoch of 1970-01-01T00:00:00Z.

Use the following API to get the current epoch time:

Copy

Monotonic Time

The monotonic time represents the number of seconds from an unspecified epoch.

Use the following API to get the monotonic time from an unspecified topic:

Copy

Civil Time

The localized time represents using the time:Civil record. It includes the following details:

  • date
  • time
  • timezone information
  • daylight time-saving information

APIs

Parallel to the aforementioned time representations, this module includes a set of APIs to facilitate time conversions and manipulations using a set of high-level APIs. Those conversion APIs can be listed as follows.

The String Representations of UTC

Copy

The String Representations of Civil

Copy

UTC Value Manipulation

Copy

UTC vs Civil

Copy

Other versions

See more...