File: Tivoli.pm

package info (click to toggle)
libdatetime-format-builder-perl 0.8300-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 504 kB
  • sloc: perl: 1,236; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 719 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# we need to comment this out or PAUSE might index it
# pack age DateTime::Format::Tivoli;

use DateTime::Format::Builder (
    parsers => {
        parse_datetime => {
            strptime => '%h %e %k:%M:%S %Y',
        },
    },
);

sub format_datetime {
    my ( $self, $dt ) = @_;
    my $z = $dt->clone->set_time_zone('GMT');
    return $z->strftime('%h %e %k:%M:%S %Y');
}

package main;

my $parser = DateTime::Format::Tivoli->new();

my @dates = ( 'Nov  5 22:49:45 2003', '27/Apr/2003:19:45:11 -0400' );

for my $date (@dates) {
    my $dt
        = $parser->parse_datetime($date)->set_time_zone('Australia/Sydney');
    print "$date => ", $dt->datetime, " => ", $parser->format_datetime($dt),
        "\n";
}