The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DR::DateTime - Easy DateTime implementator.

SYNOPSIS

  use DR::DateTime;
  my $t = new DR::DateTime time;
  my $t = new DR::DateTime time, '+0300';

  my $t = parse DR::DateTime '2017-08-18 12:33:19.1234+0300';

  $t->year;
  $t->month;
  $t->day;
  $t->day_of_week;
  $t->hour;
  $t->minute;
  $t->second;
  $t->nanosecond;

  $t->add(second => 15, hour => 24, month => 17);
  $t->subtract(year => 7);

DESCRIPTION

The module provide the same (reduced) API as DateTime.

DateTime is a very usable and good module, but Dump of its objects gets two or three screens, so If You use more than one object DateTime You have too many troubles to debug Your code.

METHODS

new([$timestamp[,$timezone]])

Create DR::DateTime instance. If $timezone is not defined, the module will use $DR::DateTime::Defaults::TZ value.

$timezone is used only for "strftime" method.

parse($str[, $default_timezone])

Default value for $default_timezone is '+0000' (UTC).

Parse string and creates and object (or return undef).

The module can parse only standard time format like (may be partly incompleted) %F %T.%N %z (see man strftime).

strftime($format)

Method that works like "strftime" in POSIX. The method has one additional placeholder - %N - nanosecond.

nanosecond, second, etc

Methods that return part of contained date. Allow:

nanosecond
second
minute
hour
day
day_of_week ($t->strftime('%u'))
month
year

truncate(to => ...)

This method allows You to reset some of the local time components in the object to their "zero" values. The "to" parameter is used to specify which values to truncate, and it may be one of year, month, day, hour, minute, or second.

add(...), substract(...)

These methods allow You add or substract values to object.

    $t
        -> add(
            year        => 1,
            month       => 2,
            day         => 4,
            hour        => 17,
            minute      => 18,
            second      => 19,
            nanosecond  => 50001
        )
        -> subtract(
            year        => 3,
            month       => 4,
            day         => 5,
            hour        => 22,
            minute      => 23,
            second      => 24,
            nanosecond  => 7829
        );
        

time_zone or tz

Return timezone that is used for strftime method.

Now DR::DateTime uses only one time zone format: qr/^[+-]\d{2,4}$/. Named time zones are not supported yet.

epoch

Retrun timestamp value.

hires_epoch or fepoch

Return timestamp that includes nanoseconds as float value.

set_time_zone($tz)

Set timezone for the following "strftime" calls.

clone

Clone the value.

SEE ALSO

man strftime
"strftime" in POSIX

AUTHOR

Dmitry E. Oboukhov, <unera@debian.org>

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Dmitry E. Oboukhov

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.