Class-Date

 view release on metacpan or  search on metacpan

README.mkdn  view on Meta::CPAN

$date->hms          # 01:23:45
$date->ymd          # 2000/02/29
$date->mdy          # 02/29/2000
$date->dmy          # 29/02/2000
$date->meridiam     # 01:23 AM
$date->ampm         # AM/PM
$date->string       # 2000-02-29 12:21:11 (format can be changed, look below)
"$date"             # same as prev.
$date->tzoffset     # timezone-offset
$date->strftime($format) # POSIX strftime (without the huge POSIX.pm)
$date->tz           # returns the base timezone as you specify, eg: CET
$date->tzdst        # returns the real timezone with dst information, eg: CEST

($year,$month,$day,$hour,$min,$sec)=$date->array;
($year,$month,$day,$hour,$min,$sec)=@{ $date->aref };
# !! $year: 1900-, $month: 1-12

($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=$date->struct;
($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=@{ $date->sref };
# !! $year: 0-, $month: 0-11

README.mkdn  view on Meta::CPAN

ignoring the effect of DST.

When $DST\_ADJUST is set to false, then no adjustment is done, the
calculation will be based on the exact time difference.

You will see the difference through an example:

```
$Class::Date::DST_ADJUST=1;

print date("2000-10-29", "CET") + "1D";
# This will print 2000-10-30 00:00:00

print date("2001-03-24 23:00:00", "CET") + "1D";
# This will be 2001-03-25 23:00:00

print date("2001-03-25", "CET") + "1D";
# This will be 2001-03-26 00:00:00


$Class::Date::DST_ADJUST=0;

print date("2000-10-29", "CET") + "1D";
# This will print 2000-10-29 23:00:00

print date("2001-03-24 23:00:00", "CET") + "1D";
# This will be 2001-03-26 00:00:00
```

# MONTHS AND YEARS

If you add or subtract "months" and "years" to a date, you may get wrong 
dates, e.g when you add one month to 2001-01-31, you expect to get
2001-02-31, but this date is invalid and converted to 2001-03-03. Thats' why

```

lib/Class/Date.pm  view on Meta::CPAN

  $date->hms          # 01:23:45
  $date->ymd          # 2000/02/29
  $date->mdy          # 02/29/2000
  $date->dmy          # 29/02/2000
  $date->meridiam     # 01:23 AM
  $date->ampm         # AM/PM
  $date->string       # 2000-02-29 12:21:11 (format can be changed, look below)
  "$date"             # same as prev.
  $date->tzoffset     # timezone-offset
  $date->strftime($format) # POSIX strftime (without the huge POSIX.pm)
  $date->tz           # returns the base timezone as you specify, eg: CET
  $date->tzdst        # returns the real timezone with dst information, eg: CEST

  ($year,$month,$day,$hour,$min,$sec)=$date->array;
  ($year,$month,$day,$hour,$min,$sec)=@{ $date->aref };
  # !! $year: 1900-, $month: 1-12

  ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=$date->struct;
  ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=@{ $date->sref };
  # !! $year: 0-, $month: 0-11

lib/Class/Date.pm  view on Meta::CPAN

when the operation switches the border of DST. With this setting, you are
ignoring the effect of DST.

When $DST_ADJUST is set to false, then no adjustment is done, the
calculation will be based on the exact time difference.

You will see the difference through an example:

  $Class::Date::DST_ADJUST=1;

  print date("2000-10-29", "CET") + "1D";
  # This will print 2000-10-30 00:00:00

  print date("2001-03-24 23:00:00", "CET") + "1D";
  # This will be 2001-03-25 23:00:00

  print date("2001-03-25", "CET") + "1D";
  # This will be 2001-03-26 00:00:00


  $Class::Date::DST_ADJUST=0;

  print date("2000-10-29", "CET") + "1D";
  # This will print 2000-10-29 23:00:00

  print date("2001-03-24 23:00:00", "CET") + "1D";
  # This will be 2001-03-26 00:00:00

=head1 MONTHS AND YEARS

If you add or subtract "months" and "years" to a date, you may get wrong 
dates, e.g when you add one month to 2001-01-31, you expect to get
2001-02-31, but this date is invalid and converted to 2001-03-03. Thats' why

  date("2001-01-31") + '1M' - '1M' != "2001-01-31"

t/50_timezone.t  view on Meta::CPAN

use Class::Date qw(date gmdate);
eval { require Env::C };
diag "Env::C version $Env::C::VERSION loaded" if not $@;

$Class::Date::DST_ADJUST=1;

ok(1);

# Class::Date::new

my $date1 = Class::Date->new([2002,05,04,0,1,2],'CET');
is $date1, "2002-05-04 00:01:02", 'date1';
is $date1->tz,    'CET',          'tz';
is $date1->tzdst, 'CEST',         'tzdst';
is $date1->epoch, 1020463262,     'epoch';

subtest 'to GMT' => sub {
    my $date2 = $date1->to_tz('GMT');
    is $date2, "2002-05-03 22:01:02", 'date2';
    is $date2->tz, 'GMT',             'tz';
    {
        local $TODO = 'known to fail on non-linux machines - GH#8';
        is $date2->tzdst, 'GMT',          'tzdst';



( run in 1.063 second using v1.01-cache-2.11-cpan-49f99fa48dc )