Limits for Gregorian time values

While trying to do some date/time arithmetic, I stumbled upon the undocumented limits of Gregorian.moment(). Note first that Gregorian.moment() seems to expect the input parameters to be in UTC time, and then the Gregorian.info() method returns the time info for the local time zone. Anyway, I'm not sure if this is intended behavior or not, but at the very least this post may be useful to someone else.

function test(params)
{
var fmt = "$1$-$2$-$3$T$4$:$5$:$6$";

// assume the date-time that was provided is legal
var Y = params.get(:year);
var m = params.get(:month);
var d = params.get(:day);
var H = params.get(:hour);
var M = params.get(:minute);
var S = params.get(:second);

var input = Lang.format(fmt,
[ Y.format("%04d"),
m.format("%02d"),
d.format("%02d"),
H.format("%02d"),
M.format("%02d"),
S.format("%02d")
]);

var moment = Gregorian.moment(params);
var info = Gregorian.info(moment, Time.FORMAT_SHORT);

var output = Lang.format(fmt,
[ info.year.format("%04d"),
info.month.format("%02d"),
info.day.format("%02d"),
info.hour.format("%02d"),
info.min.format("%02d"),
info.sec.format("%02d")
]);
Sys.println("given " + input + " got " + output + ".");
}


I set my system timezone to UTC, and then did some testing using this function. I was able to find the bounds of acceptable inputs.

test({ :year => 1989,
:month => 12,
:day => 30,
:hour => 23,
:minute => 59,
:second => 59
});

test({ :year => 1989,
:month => 12,
:day => 31,
:hour => 0,
:minute => 0,
:second => 0
});

test({ :year => 2106,
:month => 2,
:day => 7,
:hour => 6,
:minute => 28,
:second => 15
});

test({ :year => 2106,
:month => 2,
:day => 7,
:hour => 6,
:minute => 28,
:second => 16
});


The output I see is...

given 1989-12-30T23:59:59 got 1989-12-31T00:00:00.
given 1989-12-31T00:00:00 got 1989-12-31T00:00:00.
given 2106-02-07T06:28:15 got 2106-02-07T06:28:15.
given 2106-02-07T06:28:16 got 1989-12-31T00:00:00.


Travis
  • Former Member
    Former Member over 10 years ago
    2106-02-07? Built in obsolescence ;)
  • I thought it was weirder that the epoch value for Time.Moment is 1990-01-01T00:00:00 UTC.
  • What you have discovered, as much as I wanted it never to be found, is the Garmin Epoch. You see, all of the Garmin time utility functions are based on the January 1st, 1990 (Garmin's company creation date on an nice boundary).

    You may have some questions about the sanity/ego of having a different epoch value than any other system out there. To this I offer the following FAQ:

    1. Q: Why is time zero January 1st, 1990?
    A: Because that is when Garmin came into existence.

    2. Q: Why not use <INSERT ANY OTHER VALUE HERE>
    A: Because that is not when Garmin came into existence.

    (This answer from another engineer who has a few years on me)

    The time code actually converts the value to the UNIX epoch before returning the value up to Monkey C, because you're welcome. It looks like my team may need to do a little more work behind the scenes.