| 1 | package DateTime::Format::EMIUCP::DSCTS; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | DateTime::Format::EMIUCP::DSCTS - Parse DSCTS field for EMI-UCP protocol | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use DateTime::Format::EMIUCP::DSCTS; | ||
| 10 | |||
| 11 | my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('030212065530'); | ||
| 12 | print $dt->ymd; # 2012-02-03 | ||
| 13 | print $dt->hms; # 06:55:30 | ||
| 14 | |||
| 15 | $dt->set_formatter(DateTime::Format::EMIUCP::DSCTS->new); | ||
| 16 | print $dt; # 030212065530 | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | This format is a part of EMI-UCP protocol message. EMI-UCP protocol is | ||
| 21 | primarily used to connect to short message service centers (SMSCs) for mobile | ||
| 22 | telephones. | ||
| 23 | |||
| 24 | DSCTS is a string of 12 numeric characters which represents Delivery | ||
| 25 | time-stamp in ddMMyyHHmmss format. | ||
| 26 | |||
| 27 | See EMI-UCP Interface 5.2 Specification for further explanations. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | 3 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | |||
| 33 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 34 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 35 | |||
| 36 | 3 | our $VERSION = '0.0300'; | |
| 37 | |||
| 38 | 3 | ▶ | use DateTime::Format::EMIUCP; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | |||
| 40 | =head1 METHODS | ||
| 41 | |||
| 42 | =over | ||
| 43 | |||
| 44 | =item DateTime I<$dt> = $fmt->parse_datetime(Str I<$scts>) | ||
| 45 | |||
| 46 | Given a string in the pattern specified in the constructor, this method will | ||
| 47 | return a new DateTime object. | ||
| 48 | |||
| 49 | Year number below 70 means the date before year 2000. | ||
| 50 | |||
| 51 | If given a string that doesn't match the pattern, the formatter will croak. | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | 3 | ▶ | use DateTime::Format::Builder ( |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 56 | 3 | parsers => { | |
| 57 | parse_datetime => [ | ||
| 58 | { | ||
| 59 | params => [qw( day month year hour minute second )], | ||
| 60 | regex => qr/^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/, | ||
| 61 | postprocess => \&_fix_year, | ||
| 62 | }, | ||
| 63 | ] | ||
| 64 | } | ||
| 65 | 3 | ); | |
| 66 | |||
| 67 | |||
| 68 | 3 | ▶ | BEGIN { *_fix_year = \&DateTime::Format::EMIUCP::_fix_year; } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 69 | |||
| 70 | |||
| 71 | =item Str I<$scts> = $fmt->format_datetime(DateTime I<$dt>) | ||
| 72 | |||
| 73 | Given a DateTime object, this methods returns a string formatted in the | ||
| 74 | object's format. | ||
| 75 | |||
| 76 | =back | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | 1 | ▶ | sub format_datetime { |
|
Subroutine
format_datetime: called CC=1 SCAR=0.0
Pod
documented
| |||
| 81 | 1 | my ($self, $dt) = @_; | |
| 82 | 1 | return sprintf '%02d%02d%02d%02d%02d%02d', | |
| 83 | $dt->day, $dt->month, $dt->year % 100, | ||
| 84 | $dt->hour, $dt->minute, $dt->second; | ||
| 85 | }; | ||
| 86 | |||
| 87 | |||
| 88 | 3 | 1; | |
| 89 | |||
| 90 | __END__ | ||