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:

  • 1.0.0

Defined Under Namespace

Classes: Info

Constant Summary

SECONDS_PER_YEAR = 31557600

The number of seconds in one year

Since:

  • 1.0.0

SECONDS_PER_DAY = 86400

The number of seconds in one day

Since:

  • 1.0.0

SECONDS_PER_HOUR = 3600

The number of seconds in one hour

Since:

  • 1.0.0

SECONDS_PER_MINUTE = 60

The number of seconds in one minute

Since:

  • 1.0.0

DAY_SUNDAY = 1

Sunday

Since:

  • 3.0.0

DAY_MONDAY = 2

Monday

Since:

  • 3.0.0

DAY_TUESDAY = 3

Tuesday

Since:

  • 3.0.0

DAY_WEDNESDAY = 4

Wednesday

Since:

  • 3.0.0

DAY_THURSDAY = 5

Thursday

Since:

  • 3.0.0

DAY_FRIDAY = 6

Friday

Since:

  • 3.0.0

DAY_SATURDAY = 7

Saturday

Since:

  • 3.0.0

MONTH_JANUARY = 1

January

Since:

  • 3.0.0

MONTH_FEBRUARY = 2

February

Since:

  • 3.0.0

MONTH_MARCH = 3

March

Since:

  • 3.0.0

MONTH_APRIL = 4

April

Since:

  • 3.0.0

MONTH_MAY = 5

May

Since:

  • 3.0.0

MONTH_JUNE = 6

June

Since:

  • 3.0.0

MONTH_JULY = 7

July

Since:

  • 3.0.0

MONTH_AUGUST = 8

August

Since:

  • 3.0.0

MONTH_SEPTEMBER = 9

September

Since:

  • 3.0.0

MONTH_OCTOBER = 10

October

Since:

  • 3.0.0

MONTH_NOVEMBER = 11

November

Since:

  • 3.0.0

MONTH_DECEMBER = 12

December

Since:

  • 3.0.0

Months of the year collapse

Instance Method Details

duration(options) ⇒ Toybox::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.

Examples:

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

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

Parameters:

Options Hash (options):

Returns:

See Also:

Since:

  • 1.0.0


10999
11000
# File 'Monkeybrains.rb', line 10999

def duration(options)
end

info(moment, format) ⇒ Toybox::Time::Gregorian::Info

Get Info for a Moment in local time.

Examples:

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

Parameters:

Returns:

Since:

  • 1.0.0


11026
11027
# File 'Monkeybrains.rb', line 11026

def info(moment, format)
end

moment(options) ⇒ Toybox::Time::Moment

Create a Moment from a Dictionary of options.

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.

If UTC values are desired, it is necessary to account for the local UTC offset.

Examples:

Create a Moment representing midnight on the first day of

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

Parameters:

  • options (Toybox::Lang::Dictionary)

    A dictionary of options; values that would not result in a valid date are not allowed

Options Hash (options):

Returns:

See Also:

Since:

  • 1.0.0


10970
10971
# File 'Monkeybrains.rb', line 10970

def moment(options)
end

utcInfo(moment, format) ⇒ Toybox::Time::Gregorian::Info

Get Info for a Moment in UTC time.

Info

Examples:

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

Parameters:

Returns:

See Also:

Since:

  • 2.1.0


11053
11054
# File 'Monkeybrains.rb', line 11053

def utcInfo(moment, format)
end