Convtime()

From TinyMUX
Jump to navigation Jump to search

Description

FUNCTION: convtime(time string [, zonename [, precision]])

By default, this function converts a time string (of format [Ddd] Mmm DD HH:MM:SS YYYY) into an integer (possibly negative) which represents a count of seconds since Jan 01 00:00:00 1970 UTC not including leap secs. Where Ddd, if given, is the day of the week. Mmm is the month name, DD is the day of the month, HH is the hour in 24-hour time, MM is the minutes, SS is the seconds, and YYYY is the year.

Keep in mind that the year is not necessarily exactly four characters, and it can also be negative. This server provides a proleptic Gregorian calendar with a range of supported years between 27257 BC and 30826 AD. Year 0 is 1 BC, -1 is 2 BC, ..., so 27257 BC should be given as -27256. This follows the astronomical conventions.

If necessary, a Julian calendar is easily supported using this proleptic Gregorian one by just compensating for the leap year differences. Calculate A as floordiv(Year,100), then the difference in days between the Gregorian and Julian calendars is 2 - A + floordiv(A,4).

Note: The time string can also be freeform and this function will attempt to parse.

If a second argument is given, it is the zonename:

local - indicates that a conversion for timezone/DST of the 'local' server time should be applied (the default).
utc - indicates that no timezone/DST conversions should be applied. When used this way, there is a unique one-to-one relationship between an integer and it's corresponding text-string which may be useful for handling other timezones and fictional settings.

precision determines the number of fractional seconds shown. By default, no fractional seconds are shown.

Related Topics: convsecs(), secs(), time().

Examples

> say time()
You say "Wed Jun 24 10:22:54 1992"
> say convtime(Wed Jun 24 10:22:54 1992)
You say "709406574"
> say convtime(Wed Jun 24 10:22:54 1992, utc)
You say "709381374"
> say convtime(June 24th 1992 10:22:54.0001am Z)
You say "709381374"
> say convtime(Wed 24 Jun 1992 10:22:54 -0700)
You say "709406574"
> say convtime(2001-01-01T100000Q)
You say "978357600"
> say convtime(-1605-120T123456M)
You say "-112805738704"
> say convtime(23456W12-1T123456T)
You say "678039276896"

Server Differences