The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Date::Gregorian::Exact - timestamp precision extension for Date::Gregorian

SYNOPSIS

  use Date::Gregorian::Exact;

  $date =
    Date::Gregorian::Exact->new->set_ymd(1999, 12, 31)->set_hms(23, 59, 59);
  ($hr, $min, $sec) = $date->get_hms;

  if ($date->check_ymdhms($year, $month, $day, $hour, $min, $sec)) {
    # valid, $date has new value
  }
  else {
    # not valid, $date keeps old value
  }

  $delta = $date->get_seconds_since($otherdate);
  $date->add_seconds($delta);
  $date->set_localtime($time);
  $time = $date->get_localtime;

  $date->set_hour(23);
  $date->set_minute(59);
  $date->set_second(59);

  $hour = $date->get_hour;
  $min  = $date->get_minute;
  $sec  = $date->get_second;

  $date->round_seconds;
  $date->round_minutes;
  $date->round_hours;
  $date->round_days;

DESCRIPTION

Date::Gregorian::Exact is a subclass extending Date::Gregorian towards higher precision (sufficient to deal with timestamps).

As of Date::Gregorian version 0.07, this subclass is considered deprecated. Recent versions of the DateTime suite of modules offer a considerably more substantial approach to the intricacies of local clocks and timezones.

With Date::Gregorian::Exact objects, all methods of the base class Date::Gregorian work exactly as described there, except where noted below. In particular, most parameters must still be integer values.

Exceptions to this rule are add_days and get_days_since, now handling fractions of days as well as whole days, and set/get_gmtime, now no longer mapping every time of day to midnight.

Additional Methods

set/get_hms access hours, minutes and seconds. Non-integer values of seconds are allowed but not recommended, as they might introduce rounding errors.

check_ymdhms checks and, if valid, sets an exact date.

add_seconds and get_seconds_since handle time intervals much like add_days and get_days_since, only on a finer scale.

set/get_localtime convert timestamps as they would be interpreted in the current locale. This means, local timezone and daylight saving mode are taken into account like the localtime Perl function does.

Note, however, that timezones, leap seconds and daylight saving settings are not (yet) part of this module's data model. Any arithmetic on our date objects assumes an ideal calendar with days of a uniform length of 24 equally long hours. This can lead to incompatibilities with other date and time processing entities.

set_hour, set_minute, set_second, get_hour, get_minute, and get_second access the additional precision components of this extension class.

round_seconds, round_minutes, round_hours, and round_days move an arbitrary date and time to the nearest one at a seconds, minutes, hours, or days boundary, respectively. After round_days is called, get_hour, get_minute, and get_second will return zero values; after round_hours, get_minute and get_second will return zero, and so on.

DEPRECATION NOTICE

This module will not be part of Date::Gregorian distributions published after December 31, 2006.

AUTHOR

Martin Hasch <hasch-cpan-dg@cozap.com>, November 1999.

SEE ALSO

Date::Gregorian.