timex

This library extends Time class:

This library has following assumptions:

While it is true now, in 2001, it will be invalidated in some future. (20 years? 100 years?) I hope that POSIX will have better API for handling time which enables abolish these assumptions.

class methods

Time.parse(date, cyear=false)

parses date using ParseDate.parsedate and convert it to Time object. cyear is passed to ParseDate.parsedate.

When ParseDate.parsedate fails to extract some components of a broken-down time, Time.now is used for them.

Since there are various timezone abbreviations in the world, conflicts exist between some of them. For example, CST is used as -06:00 in America/Chicago, -05:00 in America/Havana, +08:00 in Asia/Harbin, +09:30 in Australia/Darwin, +10:30 in Australia/Adelaide, etc. So, it is impossible to support all of them.

This method supports timezone abbreviations described in RFC 822 and system timezone. The system timezone is taken from Time.local(year, 1, 1).zone and Time.local(year, 7, 1).zone. If the extracted timezone abbreviation doesn't match them, it is ignored and broken-down time is assumed as represented in localtime. If it matches RFC 822 and system timezone, RFC 822 is prefered.

methods

Time#utcoff
Time#gmtoff

returns difference to UTC in seconds.

Note that it returns 0 if self is UTC mode.

Time#leapsecs

returns number of leapseconds from Unix epoch.

Note that this method returns non-zero only if your system has leapseconds information. Since POSIX defines that leapseconds are not handled, most OSs doesn't handle leapseconds by default. But many OSs can handle leapseconds fairly easily in theory (but not well tested, though). For example, GNU/Linux (and various OSs) uses zoneinfo database to store leapseconds information and some GNU/Linux distributions has zoneinfo database which contains leapseconds information under /usr/share/zoneinfo/right. So, under such Linux, setting TZ environment variable is what you need to use leapseconds.

Time#rfc2822
Time#rfc822

returns a string which represents the time in RFC 2822 date format. The format is identical to RFC 822 date format modified by RFC 1123.

If self is UTC mode, the result is also complient with HTTP-date (rfc1123-date) defined by RFC 2616 which is restricted version of the date format defined by RFC 822 and RFC 1123.

Time#iso8601

returns a string which represents the time in ISO 8601 format.

However ISO 8601 defines various format for date/time, the method supports single format: YYYY-MM-DDThh:mm:ssTZD