| 1 | package Net::GPSD3::Return::Unknown::Timestamp; | ||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use base qw{Net::GPSD3::Return::Unknown}; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use DateTime::Format::W3CDTF; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | 5 | our $VERSION='0.18'; | |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | Net::GPSD3::Return::Unknown::Timestamp - Net::GPSD3 Return Base Class with Timestamp | ||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | package XXX; | ||||||||||||||||||||||||||||||||||||
| 17 | use base qw{Net::GPSD3::Return::Unknown::Timestamp}; | ||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | Provides a time, timestamp and datetime methods to a GPSD3 Return object. | ||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | =head2 time | ||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | Seconds since the Unix epoch, UTC. The value may have a fractional part of up to .01sec precision. | ||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | Note: In 2.96 (protocol 3.4) the TPV->time format changed from unix epoch to W3C, but this method attempts to hide that change from the user. | ||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||
| 31 | Since the POSIX standard for the Unix epoch does not use leap seconds but GPS system does I do not recommend that you use this method for time display or storage. This method is purely here for backwards compatibility. | ||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | sub time { | ||||||||||||||||||||||||||||||||||
|
Subroutine
time: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 36 | 3 | my $self=shift; | |||||||||||||||||||||||||||||||||||
| 37 | #protocol < 3.4 | ||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | $self->timestamp unless defined $self->{"_time"}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | $self->{"_time"}=$self->datetime->hires_epoch unless defined $self->{"_time"}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 40 | 3 | return $self->{"_time"}; | |||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | =head2 timestamp | ||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||
| 45 | W3C formated timestamp value either directly from the protocol >= 3.4 or calculated < 3.4. The value may have a fractional part of up to .01sec precision. | ||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | Note: I expect that in protocol 3.5 the value will be passed directly as TPV->timestamp | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||
| 51 | 7 | ▶ | sub timestamp { | ||||||||||||||||||||||||||||||||||
|
Subroutine
timestamp: called CC=9 SCAR=29.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 52 | 7 | my $self=shift; | |||||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | unless (defined $self->{"_timestamp"}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 54 | 3 | my $qr=qr/\A\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?Z\Z/; | |||||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | if (defined($self->{"timestamp"}) and $self->{"timestamp"} =~ $qr) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
defined $self->{"timestamp"} and $self->{"timestamp"} =~ /$qr/
MC/DC50%1/2
defined $self->{"timestamp"} and $self->{"timestamp"} =~ /$qr/
defined $self->{"timestamp"}
$self->{"timestamp"} =~ /$qr/
Truth table66%2/3
A and B
A= defined $self->{"timestamp"}B= $self->{"timestamp"} =~ /$qr/
| |||||||||||||||||||||||||||||||||||||
| 56 | #protocol 3.5 (expected) | ||||||||||||||||||||||||||||||||||||
| 57 | 2 | $self->{"_timestamp"}=$self->{"timestamp"} | |||||||||||||||||||||||||||||||||||
| 58 | ▶ | } elsif (defined($self->{"time"}) and $self->{"time"} =~ $qr) { | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $self->{"time"} and $self->{"time"} =~ /$qr/
MC/DC0%0/2
defined $self->{"time"} and $self->{"time"} =~ /$qr/
defined $self->{"time"}
$self->{"time"} =~ /$qr/
Truth table33%1/3
A and B
A= defined $self->{"time"}B= $self->{"time"} =~ /$qr/
| |||||||||||||||||||||||||||||||||||||
| 59 | #protocol 3.4 | ||||||||||||||||||||||||||||||||||||
| 60 | 1 | $self->{"_timestamp"}=$self->{"time"}; | |||||||||||||||||||||||||||||||||||
| 61 | ▶ | } elsif (defined($self->{"time"}) and $self->{"time"} =~ m/^\d{1,}(?:\.\d*)?$/) { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $self->{"time"} and $self->{"time"} =~ /^\d{1,}(?:\.\d*)?$/
MC/DC0%0/2
defined $self->{"time"} and $self->{"time"} =~ /^\d{1,}(?:\.\d*)?$/
defined $self->{"time"}
$self->{"time"} =~ /^\d{1,}(?:\.\d*)?$/
Truth table0%0/3
A and B
A= defined $self->{"time"}B= $self->{"time"} =~ /^\d{1,}(?:\.\d*)?$/
| |||||||||||||||||||||||||||||||||||||
| 62 | #protocol < 3.4 | ||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $self->{"_time"}=$self->{"time"} unless defined $self->{"_time"}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 64 | 0 | $self->{"_timestamp"}=$self->datetime->strftime(q{%FT%T.%2NZ}); #%2N truncates should round DateTime 0.66 | |||||||||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||||||||||
| 66 | 0 | die("Error: Either TPV->timestamp or TPV->time must be defined."); | |||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||
| 69 | 7 | return $self->{"_timestamp"}; | |||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||
| 72 | =head2 datetime | ||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||
| 74 | Returns a L<DateTime> object | ||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | 11 | ▶ | sub datetime { | ||||||||||||||||||||||||||||||||||
|
Subroutine
datetime: called CC=8 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 79 | 11 | my $self=shift; | |||||||||||||||||||||||||||||||||||
| 80 | 11 | ▶ | unless (defined($self->{"datetime"})) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 81 | my $timestamp=$self->{"_timestamp"} || | ||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | $self->{"timestamp"} || #protocol >= 3.5 (expected) | ||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->{'_timestamp'} || $self->{'timestamp'} || undef
$self->{"_timestamp"} or $self->{"timestamp"}
MC/DC0%0/2
$self->{'_timestamp'} || $self->{'timestamp'} || undef
$self->{"_timestamp"}
$self->{"timestamp"}
Truth table33%1/3
A or B
A= $self->{"_timestamp"}B= $self->{"timestamp"}
| |||||||||||||||||||||||||||||||||||||
| 83 | undef; | ||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | if (defined $timestamp) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 85 | 3 | $self->{"datetime"}=DateTime::Format::W3CDTF->new->parse_datetime($timestamp); | |||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | $self->{"_time"}=$self->datetime->hires_epoch unless defined $self->{"_time"}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 87 | } elsif (defined $self->{"_time"}) { | ||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->{"datetime"}=DateTime->from_epoch(epoch=>$self->{"_time"}, time_zone=>"UTC"); | |||||||||||||||||||||||||||||||||||
| 89 | } elsif ($self->timestamp) { #infinate loop potential | ||||||||||||||||||||||||||||||||||||
| 90 | 0 | $self->{"datetime"}=DateTime::Format::W3CDTF->new->parse_datetime($self->timestamp); | |||||||||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||||||||||
| 92 | 0 | die("Error: Either TPV->timestamp or TPV->time must be defined."); | |||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||
| 95 | 11 | return $self->{"datetime"}; | |||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||
| 98 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||
| 100 | Log on RT and Send to gpsd-dev email list | ||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||
| 102 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||
| 104 | DavisNetworks.com supports all Perl applications including this package. | ||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | Try gpsd-dev email list | ||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||
| 108 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||
| 110 | Michael R. Davis | ||||||||||||||||||||||||||||||||||||
| 111 | CPAN ID: MRDVT | ||||||||||||||||||||||||||||||||||||
| 112 | STOP, LLC | ||||||||||||||||||||||||||||||||||||
| 113 | domain=>michaelrdavis,tld=>com,account=>perl | ||||||||||||||||||||||||||||||||||||
| 114 | http://www.stopllc.com/ | ||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||
| 118 | This program is free software licensed under the... | ||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | The BSD License | ||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||
| 124 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||
| 126 | L<Net::GPSD3>, L<Net::GPSD3::Return::Unknown>, L<DateTime::Format::W3CDTF>, L<DateTime> | ||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | 5 | 1; | |||||||||||||||||||||||||||||||||||