Heikki Mehtänen > Date-Parser-0.4 > Date::Parser

Download:
Date-Parser-0.4.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.4   Source  

NAME ^

Date::Parser - Simple date parsing

VERSION ^

Version 0.4

SYNOPSIS ^

  my $dp = Date::Parser->new;
  my $format = "%b %d %H:%M:%S";
  open(my $fh, "<", "/var/log/sshd.log") or die "failed to open log: $!";
  while (my $line = readline($fh)) {
      chomp($line);
      my $date = $dp->parse_data($format, $line);
      # do something with the date ..
  }
  close($fh);

DESCRIPTION ^

Really simple date parsing factory. Uses I18N::Langinfo for localized day/month names and abbreviations.

METHODS ^

parse_data($format, $data)

Parses given $data using $format.

Returns a new Date::Parser::Date -object.

FORMAT ^

For parsing you can use the following formatting:

        %%      literal %, is not captured.
        %a      day of the week abbr
        %A      day of the week
        %b      month abbr
        %B      month
        %d      numeric day of the month, with leading zeros (eg 01..31)
        %e      like %d, but a leading zero is replaced by a space (eg  1..32)
        %h      month abbr
        %H      hour, 24 hour clock, leading 0's
        %I      hour, 12 hour clock, leading 0's
        %j      day of the year
        %k      hour
        %l      hour, 12 hour clock
        %L      month number, starting with 1
        %m      month number, starting with 01
        %M      minute, leading 0's
        %o      ornate day of month - "1st", "2nd", etc. (only day int is captured)
        %p      AM or PM (both %p or %P and %I or %l are required ..)
        %P      am or pm (.. to resolve 12 hour clock time.)
        %q      Quarter number, starting with 1
        %s      seconds since the Epoch, UCT
        %S      seconds, leading 0's
        %t      TAB, is not captured
        %U      week number, Sunday as first day of week
        %w      day of the week, numerically, Sunday == 0
        %W      week number, Monday as first day of week
        %y      year (2 digits, e.g. 11 => 2011)
        %Y      year (4 digits)
        %Z      timezone in ascii. eg: PST
        %z      timezone in format -/+0000

CAVEATS ^

Still under work, so missing some features.. works for most log formats pretty well.

TODO ^

  - Day of week (in case doy is missing)
  - Localized values for ornate dom
  - Quarter support (in case month is missing)
  - Week number support (in case month/doy is missing)
  - Timezones (?)

AUTHOR ^

Heikki Mehtänen, <heikki@mehtanen.fi>

COPYRIGHT & LICENSE ^

Copyright 2011 Heikki Mehtänen, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: