NAME
Date::Reformat - Rearrange date strings
SYNOPSIS
use Date::Reformat;
my $parser = Date::Reformat->new(
parser => {
regex => qr/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)$/,
params => [qw(year month day hour minute second)],
},
defaults => {
time_zone => 'America/New_York',
},
transformations => [
{
from => 'year',
to => 'century',
coderef => sub { int($_[0] / 100) },
},
],
formatter => {
sprintf => '%s-%02d-%02dT%02d:%02d:02d %s',
params => [qw(year month day hour minute second time_zone)],
},
);
my $parser = Date::Reformat->new(
parser => {
strptime => '%Y-%m-%dT%M:%H:%S',
# or heuristic => 'ymd', # http://www.postgresql.org/docs/9.2/static/datetime-input-rules.html
},
defaults => {
time_zone => 'America/New_York',
},
formatter => {
strftime => '%Y-%m-%dT%M:%H:%S %Z',
# or data_structure => 'hashref' || 'hash' || 'arrayref' || 'array'
# or coderef => sub { my ($y, $m, $d) = @_; DateTime->new(year => $y, month => $m, day => $d) },
# params => [qw(year month day)],
},
);
my $reformatted_string = $parser->reformat_date($date_string);
DESCRIPTION
This module aims to be a lightweight and flexible tool for rearranging components of a date string, then returning the components in the order and structure specified.
METHODS
- new()
- initialize_parser()
- initialize_formatter()
- initialize_transformations()
- initialize_defaults()
- initialize_debug()
- initialize_parser_for_regex_with_params()
- initialize_parser_for_regex_named_capture()
- initialize_parser_for_strptime()
- initialize_parser_heuristic()
- initialize_formatter_for_arrayref()
- initialize_formatter_for_hashref()
- initialize_formatter_for_coderef()
- initialize_formatter_for_sprintf()
- initialize_formatter_for_strftime()
- strptime_token_to_regex()
- strftime_token_to_internal
- transform_token_value()
- most_likely_token()
- add_parser()
- add_formatter()
- parse_date()
- format_date()
- reformat_date()
SEE ALSO
AUTHOR
Nathan Gray <kolibrie@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2015 by Nathan Gray
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.