Determine current time in UTC correctly
Version: 0.006Time::UTC::Now is a Perl module to determine current time in UTC correctly.
License: Perl Artistic License
Operating System: Linux
use Time::UTC::Now qw(now_utc_rat now_utc_sna now_utc_flt);
($day, $secs, $bound) = now_utc_rat;
($day, $secs, $bound) = now_utc_rat(1);
($day, $secs, $bound) = now_utc_sna;
($day, $secs, $bound) = now_utc_sna(1);
($day, $secs, $bound) = now_utc_flt;
($day, $secs, $bound) = now_utc_flt(1);
use Time::UTC::Now qw(utc_day_to_mjdn utc_day_to_cjdn);
$mjdn = utc_day_to_mjdn($day);
$cjdn = utc_day_to_cjdn($day);
This module is one answer to the question "what time is it?". It determines the current time on the UTC scale, handling leap seconds correctly, and puts a bound on how inaccurate it could be. It is the rigorously correct approach to determining civil time. It is designed to interoperate with Time::UTC, which knows all about the UTC time scale.
UTC (Coordinated Universal Time) is a time scale derived from International Atomic Time (TAI). UTC divides time up into days, and each day into seconds. The seconds are atomically-realised SI seconds, of uniform length. Most UTC days are exactly 86400 seconds long, but occasionally there is a day of length 86401 s or (theoretically) 86399 s. These leap seconds are used to keep the UTC day approximately synchronised with the non-uniform rotation of the Earth. (Prior to 1972 a different mechanism was used for UTC, but that's not an issue here.)
Because UTC days have differing lengths, instants on the UTC scale are identified here by the combination of a day number and a number of seconds since midnight within the day. In this module the day number is the integral number of days since 1958-01-01, which is the epoch of the TAI scale which underlies UTC. This is the convention used by the Time::UTC module. That module has some functions to format these numbers for display. For a more general solution, use the utc_day_to_mjdn function to translate to a standard Modified Julian Day Number or the utc_day_to_cjdn function to translate to a standard Chronological Julian Day Number, which can be used as input to a calendar module.