Permalink
Browse files

New filter for DSCTS field for EMI-UCP protocol

  • Loading branch information...
1 parent 295f516 commit 2125a0d16296dc3acca36c7d37bcd223a64870e7 @dex4er committed Apr 19, 2012
View
@@ -1,4 +1,9 @@
------------------------------------------------------------------------
+0.0300 | Piotr Roszatycki <dexter@cpan.org> | 2012-04-19
+
+* New filter for DSCTS field for EMI-UCP protocol.
+
+------------------------------------------------------------------------
0.0200 | Piotr Roszatycki <dexter@cpan.org> | 2012-04-15
* Separate filters for SCTS, DDT and VP fields for EMI-UCP protocol.
@@ -25,6 +25,9 @@ telephones.
SCTS is a string of 12 numeric characters which represents Service Center
time-stamp in ddMMyyHHmmss format.
+DSCTS is a string of 12 numeric characters which represents Delivery
+time-stamp in ddMMyyHHmmss format.
+
DDT is a string of 10 numeric characters which represents deferred delivery
time in ddMMyyHHmm format.
@@ -42,7 +45,7 @@ use 5.006;
use strict;
use warnings;
-our $VERSION = '0.0200';
+our $VERSION = '0.0300';
=head1 METHODS
@@ -105,8 +108,11 @@ L<DateTime::Format::Builder>
=head1 SEE ALSO
-L<DateTime::Format::EMIUCP::DDT>, L<DateTime::Format::EMIUCP::SCTS>,
-L<DateTime::Format::EMIUCP::VP>, L<DateTime>.
+L<DateTime::Format::EMIUCP::DDT>,
+L<DateTime::Format::EMIUCP::DSCTS>,
+L<DateTime::Format::EMIUCP::SCTS>,
+L<DateTime::Format::EMIUCP::VP>,
+L<DateTime>.
=head1 BUGS
@@ -26,16 +26,14 @@ time in ddMMyyHHmm format.
See EMI-UCP Interface 5.2 Specification for further explanations.
-=for readme stop
-
=cut
use 5.006;
use strict;
use warnings;
-our $VERSION = '0.0200';
+our $VERSION = '0.0300';
use DateTime::Format::EMIUCP;
@@ -91,8 +89,6 @@ sub format_datetime {
__END__
-=for readme continue
-
=head1 PREREQUISITES
=over 2
@@ -0,0 +1,125 @@
+package DateTime::Format::EMIUCP::DSCTS;
+
+=head1 NAME
+
+DateTime::Format::EMIUCP::DSCTS - Parse DSCTS field for EMI-UCP protocol
+
+=head1 SYNOPSIS
+
+ use DateTime::Format::EMIUCP::DSCTS;
+
+ my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('030212065530');
+ print $dt->ymd; # 2012-02-03
+ print $dt->hms; # 06:55:30
+
+ $dt->set_formatter(DateTime::Format::EMIUCP::DSCTS->new);
+ print $dt; # 030212065530
+
+=head1 DESCRIPTION
+
+This format is a part of EMI-UCP protocol message. EMI-UCP protocol is
+primarily used to connect to short message service centers (SMSCs) for mobile
+telephones.
+
+DSCTS is a string of 12 numeric characters which represents Delivery
+time-stamp in ddMMyyHHmmss format.
+
+See EMI-UCP Interface 5.2 Specification for further explanations.
+
+=cut
+
+use 5.006;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.0300';
+
+use DateTime::Format::EMIUCP;
+
+=head1 METHODS
+
+=over
+
+=item DateTime I<$dt> = $fmt->parse_datetime(Str I<$scts>)
+
+Given a string in the pattern specified in the constructor, this method will
+return a new DateTime object.
+
+Year number below 70 means the date before year 2000.
+
+If given a string that doesn't match the pattern, the formatter will croak.
+
+=cut
+
+use DateTime::Format::Builder (
+ parsers => {
+ parse_datetime => [
+ {
+ params => [qw( day month year hour minute second )],
+ regex => qr/^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/,
+ postprocess => \&_fix_year,
+ },
+ ]
+ }
+);
+
+
+BEGIN { *_fix_year = \&DateTime::Format::EMIUCP::_fix_year; }
+
+
+=item Str I<$scts> = $fmt->format_datetime(DateTime I<$dt>)
+
+Given a DateTime object, this methods returns a string formatted in the
+object's format.
+
+=back
+
+=cut
+
+sub format_datetime {
+ my ($self, $dt) = @_;
+ return sprintf '%02d%02d%02d%02d%02d%02d',
+ $dt->day, $dt->month, $dt->year % 100,
+ $dt->hour, $dt->minute, $dt->second;
+};
+
+
+1;
+
+__END__
+
+=head1 PREREQUISITES
+
+=over 2
+
+=item *
+
+L<DateTime::Format::Builder>
+
+=back
+
+=head1 SEE ALSO
+
+L<DateTime>.
+
+=head1 BUGS
+
+If you find the bug or want to implement new features, please report it at
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DateTime-Format-EMIUCP>
+
+The code repository is available at
+L<http://github.com/dex4er/perl-DateTime-Format-EMIUCP>
+
+=head1 AUTHOR
+
+Piotr Roszatycki <dexter@cpan.org>
+
+=head1 LICENSE
+
+Copyright (c) 2012 Piotr Roszatycki <dexter@cpan.org>.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as perl itself.
+
+See L<http://dev.perl.org/licenses/artistic.html>
@@ -26,16 +26,14 @@ time-stamp in ddMMyyHHmmss format.
See EMI-UCP Interface 5.2 Specification for further explanations.
-=for readme stop
-
=cut
use 5.006;
use strict;
use warnings;
-our $VERSION = '0.0200';
+our $VERSION = '0.0300';
use DateTime::Format::EMIUCP;
@@ -91,8 +89,6 @@ sub format_datetime {
__END__
-=for readme continue
-
=head1 PREREQUISITES
=over 2
@@ -26,16 +26,14 @@ in ddMMyyHHmm format.
See EMI-UCP Interface 5.2 Specification for further explanations.
-=for readme stop
-
=cut
use 5.006;
use strict;
use warnings;
-our $VERSION = '0.0200';
+our $VERSION = '0.0300';
use DateTime::Format::EMIUCP;
@@ -91,8 +89,6 @@ sub format_datetime {
__END__
-=for readme continue
-
=head1 PREREQUISITES
=over 2
View
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Carp ();
+
+$SIG{__WARN__} = sub { local $Carp::CarpLevel = 1; Carp::confess("Warning: ", @_) };
+
+use Test::More tests => 12;
+
+BEGIN { use_ok 'DateTime::Format::EMIUCP::DSCTS' }
+
+do {
+ my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('030212065530');
+ isa_ok $dt, 'DateTime';
+ is $dt->ymd, '2012-02-03', 'date';
+ is $dt->hms, '06:55:30', 'time';
+};
+
+do {
+ my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('010100010101');
+ isa_ok $dt, 'DateTime';
+ is $dt->year, 2000, 'year';
+};
+
+do {
+ my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('010199010101');
+ isa_ok $dt, 'DateTime';
+ is $dt->year, 1999, 'year';
+};
+
+do {
+ my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('010170010101');
+ isa_ok $dt, 'DateTime';
+ is $dt->year, 1970, 'year';
+};
+
+do {
+ my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('010169010101');
+ isa_ok $dt, 'DateTime';
+ is $dt->year, 2069, 'year';
+};
View
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Carp ();
+
+$SIG{__WARN__} = sub { local $Carp::CarpLevel = 1; Carp::confess("Warning: ", @_) };
+
+use Test::More tests => 3;
+
+use Test::Exception;
+
+BEGIN { use_ok 'DateTime::Format::EMIUCP::DSCTS' }
+
+throws_ok { my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('010203040599') }
+ qr/an integer between 0 and 61/, 'wrong date';
+
+throws_ok { my $dt = DateTime::Format::EMIUCP::DSCTS->parse_datetime('INVALID') }
+ qr/Invalid date format/, 'invalid format';
View
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Carp ();
+
+$SIG{__WARN__} = sub { local $Carp::CarpLevel = 1; Carp::confess("Warning: ", @_) };
+
+use Test::More tests => 5;
+
+BEGIN { use_ok 'DateTime::Format::EMIUCP::DSCTS' }
+
+my $dt = DateTime->new(
+ year => 2012,
+ month => 2,
+ day => 3,
+ hour => 6,
+ minute => 55,
+ second => 30,
+ time_zone => 'UTC',
+);
+isa_ok $dt, 'DateTime';
+is $dt->ymd, '2012-02-03', 'date';
+is $dt->hms, '06:55:30', 'time';
+is(DateTime::Format::EMIUCP::DSCTS->format_datetime($dt), '030212065530', 'format_datetime');

0 comments on commit 2125a0d

Please sign in to comment.