NAME
DateTime::Format::Strptime - Parse and format strp and strf time patterns
SYNOPSIS
use DateTime::Format::Strptime;
my $Strp = new DateTime::Format::Strptime(
pattern => '%T',
language => 'English',
time_zone => 'Melbourne/Australia',
);
my $dt = $Strp->parse_datetime('23:16:42');
$Strp->format_datetime($dt);
# 23:16:42
DESCRIPTION
This module replicates most of Strptime for DateTime. Strptime is the unix command that is the reverse of Strftime. While Strftime takes a DateTime and outputs it in a given format, Strptime takes a DateTime and a format and returns the DateTime object associated.
CONSTRUCTOR
new( format=>$strptime_pattern )
Creates the format object. You must specify a pattern, you can also specify a
time_zone
andlanguage
.
METHODS
This class offers the following methods.
parse_datetime($string)
Given a string in the format specified in the constructor, this method will return a new
DateTime
object.If given a string that doesn't match the format, the formatter will croak.
format_datetime($datetime)
Given a
DateTime
object, this methods returns a string formatted in the object's format.language($language)
When given a language, this method sets its language appropriately.
This method returns the current language. (After processing as above)
pattern($strptime_pattern)
When given a format, this method sets the object's format.
This method returns the current format. (After processing as above)
EXPORTS
There are no methods exported by default, however the following are available:
strptime($strptime_pattern, $string)
Given a format and a string this function will return a new
DateTime
object.strftime($strptime_pattern, $datetime)
Given a format and a
DateTime
object this function will return a formatted string.
PATTERN TOKENS
The following tokens are allowed in the format string:
%%
The % character.
%a or %A
The weekday name according to the current locale, in abbreviated form or the full name.
%b or %B or %h
The month name according to the current locale, in abbreviated form or the full name.
%C
The century number (0-99).
%d or %e
The day of month (1-31).
%D
Equivalent to %m/%d/%y. (This is the American style date, very confusing to non-Americans, especially since %d/%m/%y is widely used in Europe. The ISO 8601 standard format is %Y-%m-%d.)
%g
The year corresponding to the ISO week number, but without the century (0-99).
%G
The year corresponding to the ISO week number.
%H
The hour (0-23).
%I
The hour on a 12-hour clock (1-12).
%j
The day number in the year (1-366).
%m
The month number (1-12).
%M
The minute (0-59).
%n
Arbitrary whitespace.
%p
The equivalent of AM or PM according to the language in use. (See DateTime::Language)
%r
Equivalent to %I:%M:%S %p.
%R
Equivalent to %H:%M.
%s
Number of seconds since the Epoch.
%S
The second (0-60; 60 may occur for leap seconds. See DateTime::LeapSecond).
%t
Arbitrary whitespace.
%T
Equivalent to %H:%M:%S.
%U
The week number with Sunday the first day of the week (0-53). The first Sunday of January is the first day of week 1.
%u
The weekday number (1-7) with Monday = 1. This is the DateTime standard.
%w
The weekday number (0-6) with Sunday = 0.
%W
The week number with Monday the first day of the week (0-53). The first Monday of January is the first day of week 1.
%y
The year within century (0-99). When a century is not otherwise specified, values in the range 69-99 refer to years in the twen- tieth century (1969-1999); values in the range 00-68 refer to years in the twenty-first century (2000-2068).
%Y
The year, including century (for example, 1991).
%z
An RFC-822/ISO 8601 standard time zone specification. (For example +1100) [See note below]
%Z
The timezone name. (For example EST -- which is ambiguous) [See note below]
NOTES
strftime
All references to strftime are just aliases to the
DateTime-
strftime> method. SeeDateTime
for more informationTime Zones
While the tokens %z and %Z accept time zone information, these are not used. You must set your object's timezone if you set these. Why? Each has its own reason: %z is an offset, but we can't tell if we're in DST until too late, so we can't use it to create our object. %Z is an ambiguous name for a time zone. There's an EST in Australia and in the USA. To fix this ambiguity strftime should add a token for Olsen style time zones. Oh well! If anyone wants to take a look at time zone parsing, be my guest. It should be used for checking and creating the objects in the code. Then we should set_timezone back to the object's zone just before returning it.
SUPPORT
Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details.
Alternatively, log them via the CPAN RT system via the web or email:
http:// bug-datetime-format-strptime@rt.cpan.org
This makes it much easier for me to track things and thus means your problem is less likely to be neglected.
LICENSE AND COPYRIGHT
Copyright © Rick Measham, 2003. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the licenses can be found in the LICENCE file included with this module.
AUTHOR
Rick Measham <rickm@cpan.org>
SEE ALSO
datetime@perl.org
mailing list.
http://datetime.perl.org/
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 770:
'=item' outside of any '=over'
- Around line 788:
You forgot a '=back' before '=head1'