Module: Toybox.Time.Gregorian

Overview

The Gregorian module provides an interface for getting Moment objects and Duration objects based on the Gregorian calendar.

For convenience, several time constants are defined that represent the number of seconds per year, per day, per hour, and per minute.

See Also:

Since:

API Level 1.0.0

Classes Under Namespace

Classes: Info

Constant Summary

Constant Variables

Type Name Value Since Description
Type SECONDS_PER_DAY 86400

API Level 1.0.0

The number of seconds in one day

Type SECONDS_PER_HOUR 3600

API Level 1.0.0

The number of seconds in one hour

Type SECONDS_PER_MINUTE 60

API Level 1.0.0

The number of seconds in one minute

Type SECONDS_PER_YEAR 31557600

API Level 1.0.0

The number of seconds in one year

DayOfWeek

Since:

API Level 1.0.0

Name Value Since Description See Also
DAY_SUNDAY 1

API Level 3.0.0

Sunday

DAY_MONDAY 2

API Level 3.0.0

Monday

DAY_TUESDAY 3

API Level 3.0.0

Tuesday

DAY_WEDNESDAY 4

API Level 3.0.0

Wednesday

DAY_THURSDAY 5

API Level 3.0.0

Thursday

DAY_FRIDAY 6

API Level 3.0.0

Friday

DAY_SATURDAY 7

API Level 3.0.0

Saturday

Month

Since:

API Level 1.0.0

Name Value Since Description See Also
MONTH_JANUARY 1

API Level 3.0.0

January

MONTH_FEBRUARY 2

API Level 3.0.0

February

MONTH_MARCH 3

API Level 3.0.0

March

MONTH_APRIL 4

API Level 3.0.0

April

MONTH_MAY 5

API Level 3.0.0

May

MONTH_JUNE 6

API Level 3.0.0

June

MONTH_JULY 7

API Level 3.0.0

July

MONTH_AUGUST 8

API Level 3.0.0

August

MONTH_SEPTEMBER 9

API Level 3.0.0

September

MONTH_OCTOBER 10

API Level 3.0.0

October

MONTH_NOVEMBER 11

API Level 3.0.0

November

MONTH_DECEMBER 12

API Level 3.0.0

December

Instance Method Summary collapse

Instance Method Details

duration(options as { :years as Lang.Number, :days as Lang.Number, :hours as Lang.Number, :minutes as Lang.Number, :seconds as Lang.Number }) as Time.Duration

Create a Duration from a Dictionary of options.

This is an alternative to Duration.initialize() that allows the Duration to be made more easily, using familiar units, which can be handy when building a Duration manually.

Option values are represented as signed 32-bit integers.

Parameters:

  • options(Lang.Dictionary)

    A dictionary of options

    • :years(Lang.Number)

      The number of years (max 69)

    • :days(Lang.Number)

      The number of days (max 24855)

    • :hours(Lang.Number)

      The number of hours (max 596523)

    • :minutes(Lang.Number)

      The number of minutes (max 35791394)

    • :seconds(Lang.Number)

      The number of seconds (max 2147483647)

Example:

Create a Duration of one day with Gregorian.duration()

using Toybox.Time.Gregorian;
var oneDay = Gregorian.duration({:days => 1});

Returns:

  • Time.Duration

    The Duration representing the specified span of time

See Also:

Since:

API Level 1.0.0

info(moment as Time.Moment or Time.LocalMoment, format as Time.DateFormat) as Gregorian.Info

Get Info for a Moment in local time.

Parameters:

Example:

Get Info for today in local time (assume CST)

using Toybox.System;
using Toybox.Time;
using Toybox.Time.Gregorian;
var options = {
    :year   => 2003,
    :month  => 5, // 3.x devices can also use :month => Gregorian.MONTH_MAY
    :day    => 16,
    :hour   => 0
};
var date = Gregorian.moment(options);
var birthday = Gregorian.info(date, Time.FORMAT_MEDIUM);
System.println(birthday.year);  // 2003
System.println(birthday.month); // May
System.println(birthday.day);   // 16
System.println(birthday.hour);  // 19

Returns:

  • Gregorian.Info

    Info for the supplied Moment formatted according to the specified format type in local time.

Since:

API Level 1.0.0

localMoment(location as Position.Location, moment as Time.Moment) as Time.LocalMoment or Null

Create a LocalMoment from a Moment and a Location

Parameters:

  • location(Position.Location)

    The location to use to determine the time zone offset and daylight saving time rules.

  • moment(Moment)

    The UTC time to find the local time for.

Supported Devices:

Returns:

  • Time.LocalMoment

    A LocalMoment object for the local time at the given location, or null if an error occurred.

Since:

API Level 3.3.0

moment(options as { :year as Lang.Number, :month as Lang.Number or Lang.Symbol, :day as Lang.Number, :hour as Lang.Number, :minute as Lang.Number, :second as Lang.Number }) as Time.Moment

Create a Moment from a Dictionary of options.

  Each option value is assumed to be in the UTC time zone.

Unlike Moment.initialize(), which is based on the UNIX epoch, a Moment created with Gregorian.moment() is based on today(). The result is determined by taking the result of today() and overlaying the options provided.

Parameters:

Example:

Create a Moment representing midnight on the first day of the current month.

using Toybox.Time;
var oneDay = Gregorian.moment({:day => 1});

Returns:

  • Time.Moment

    A Moment representing the specified moment in time

See Also:

Since:

API Level 1.0.0

utcInfo(moment as Time.Moment, format as Time.DateFormat) as Gregorian.Info

Get Info for a Moment in UTC time.

  Info

Parameters:

Example:

Get Info for today in UTC

using Toybox.System;
using Toybox.Time;
using Toybox.Time.Gregorian;
var options = {
    :year   => 2003,
    :month  => 5, // 3.x devices can also use :month => Gregorian.MONTH_MAY
    :day    => 16,
    :hour   => 0
};
var date = Gregorian.moment(options);
var birthday = Gregorian.utcInfo(date, Time.FORMAT_MEDIUM);
System.println(birthday.year);  // 2003
System.println(birthday.month); // May
System.println(birthday.day);   // 16
System.println(birthday.hour);  // 0

Returns:

  • Gregorian.Info

    Info for the supplied Moment formatted according to the specified format type in UTC time.

See Also:

Since:

API Level 2.1.0


Generated Apr 17, 2024 9:40:38 AM