| 1 | package Image::Synchronize::Timestamp; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Image::Synchronize::Timestamp - a timestamp class | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head2 Create/Parse | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | $t = Image::Synchronize::Timestamp->new($text); | ||||||||||||||||||||||||||||
| 12 | $t2 = $t->new($text2); # $t2 and $t are unrelated | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Or create from the number of seconds since the epoch | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | $t = Image::Synchronize::Timestamp->new(6000); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Here are examples of the recognized text formats: | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | '2010:06:27 17:44:12+03:00': Exif date format, with timezone offset | ||||||||||||||||||||||||||||
| 21 | '2010-06-27 17:44:12+03:00': '-' as date separator | ||||||||||||||||||||||||||||
| 22 | '2010-06-27T17:44:12+03:00': 'T' as date/time separator: ISO 8601 | ||||||||||||||||||||||||||||
| 23 | '2010-06-27T17:44:12+03:00:00': with timezone seconds, too | ||||||||||||||||||||||||||||
| 24 | '2010:06:27 17:50:00' : no timezone offset | ||||||||||||||||||||||||||||
| 25 | '2010:06:27 17:50' : fewer time components | ||||||||||||||||||||||||||||
| 26 | '2010:06:27 17+03' : 17+03 means the same as 17:00+03:00 | ||||||||||||||||||||||||||||
| 27 | '17:44:12+03:00' : no date | ||||||||||||||||||||||||||||
| 28 | '17' : same as 17:00:00 | ||||||||||||||||||||||||||||
| 29 | '-17:44:12+03:00' : signed time | ||||||||||||||||||||||||||||
| 30 | '+17:44:12+03:00' | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Assignment/clone: | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | $t->clone; # assigns a clone | ||||||||||||||||||||||||||||
| 35 | $t2 = $t; # copies *reference*; $t and $t2 refer to the same object | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 Stringify | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | $t = Image::Synchronize::Timestamp->new('2010-06-27T17:44:12+03:00'); | ||||||||||||||||||||||||||||
| 40 | print "$t"; # (Exif) format; 2010:06:27 17:44:12+03:00 | ||||||||||||||||||||||||||||
| 41 | print $t->stringify; # same as previous | ||||||||||||||||||||||||||||
| 42 | print $t->display_iso; # ISO8601 format: 2010-06-27T17:44:12+03:00 | ||||||||||||||||||||||||||||
| 43 | print $t->display_utc; # ISO in UTC: 2010-06-27T14:44:12Z | ||||||||||||||||||||||||||||
| 44 | print $t->display_time; # no date: +354905:44:12+03:00 | ||||||||||||||||||||||||||||
| 45 | print $t->date; # Exif date (UTC) 2010:06:27 | ||||||||||||||||||||||||||||
| 46 | print $t->time; # Exif time (UTC) 14:44:12 | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head2 Query | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Number of non-leap seconds since the epoch | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | $time_local = $t->time_local; # in local timezone | ||||||||||||||||||||||||||||
| 53 | $time_utc = $t->time_utc; # in UTC | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | Timezone offset in seconds relative to UTC | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | $offset = $t->timezone_offset; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Get timezone offset for local system at given instant | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | $offset = $t->local_timezone_offset; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Check for presence of parts | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | $bool = $t->has_timezone_offset; | ||||||||||||||||||||||||||||
| 66 | $bool = $t->is_empty; | ||||||||||||||||||||||||||||
| 67 | $bool = $t->has_date; | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Check type | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Image::Synchronize::Timestamp->istypeof($t); # true | ||||||||||||||||||||||||||||
| 72 | Image::Synchronize::Timestamp->istypeof(3); # false | ||||||||||||||||||||||||||||
| 73 | $t->istypeof(3); # same as previous | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head2 Combine | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | $t = Image::Synchronize::Timestamp->new('17:44:12+03:00'); | ||||||||||||||||||||||||||||
| 78 | $t2 = $t + 30; # 17:44:42+03:00 | ||||||||||||||||||||||||||||
| 79 | $t2 = 30 + $t; # same as previous | ||||||||||||||||||||||||||||
| 80 | $t3 = $t + $t2; # ERROR: cannot add two timestamps | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | $t2 += 100; # shift forward by 100 seconds | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | $d = $t2 - $t; # 30 | ||||||||||||||||||||||||||||
| 85 | $t2 = $t - 20; # 17:43:52+03:00 | ||||||||||||||||||||||||||||
| 86 | $t3 = -$t; # -17:44:12+03:00 | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | $t3 -= 100; # shift backward by 100 seconds | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head2 Compare | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | $t1 = Image::Synchronize::Timestamp->new('+17:44:12+03:00'); | ||||||||||||||||||||||||||||
| 93 | $t2 = Image::Synchronize::Timestamp->new('+15:44:12+01:00'); | ||||||||||||||||||||||||||||
| 94 | $t3 = Image::Synchronize::Timestamp->new('+17:00:00+03:00'); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | The following five are true | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | $t1 == $t2; # same instant, also eq | ||||||||||||||||||||||||||||
| 99 | $t3 < $t1; # also <=, le, lt | ||||||||||||||||||||||||||||
| 100 | $t2 >= $t3; # also >, gt, ge | ||||||||||||||||||||||||||||
| 101 | $t3 != $t2; # not the same instant, also ne | ||||||||||||||||||||||||||||
| 102 | $t1->identical($t1); # same clock time and timezone | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | $t1 == $t2; # true: same instant | ||||||||||||||||||||||||||||
| 105 | $t1->identical($t2); # false: not same clock time and timezone | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Three-way compare | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | $t1 <=> $t2; # 0: same instant | ||||||||||||||||||||||||||||
| 110 | $t1 <=> $t3; # >0: first one is later | ||||||||||||||||||||||||||||
| 111 | $t3 <=> $t1; # <0: first one is earlier | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head2 Modify | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | $t->set_from_text($text); # replace old value | ||||||||||||||||||||||||||||
| 116 | $t->adjust_timezone_offset($offset); # shift to new timezone | ||||||||||||||||||||||||||||
| 117 | $t->adjust_to_local_timezone; # of local system at given instant | ||||||||||||||||||||||||||||
| 118 | $t->adjust_to_utc; | ||||||||||||||||||||||||||||
| 119 | $t->set_timezone_offset($offset); # keep clock time, replace timezone | ||||||||||||||||||||||||||||
| 120 | $t->remove_timezone; | ||||||||||||||||||||||||||||
| 121 | $t->adjust_nodate; # reinterpret without date | ||||||||||||||||||||||||||||
| 122 | $t->adjust_todate; # reinterpret with date | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 5 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 131 | 5 | ▶ | use Clone qw(clone); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 132 | 5 | ▶ | use Scalar::Util qw(blessed looks_like_number); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 133 | 5 | ▶ | use Time::Local v1.30 qw(timegm_modern timelocal_modern); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 5 | ▶ | use parent qw(Clone); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 136 | # Clone provides a 'clone' member | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | use overload | ||||||||||||||||||||||||||||
| 139 | 5 | ▶ | '=' => \&clone, # copy constructor: doesn't overload assignment | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 140 | '-' => \&subtract, | ||||||||||||||||||||||||||||
| 141 | '+' => \&add, | ||||||||||||||||||||||||||||
| 142 | '""' => \&stringify, | ||||||||||||||||||||||||||||
| 143 | '<=>' => \&three_way_cmp, | ||||||||||||||||||||||||||||
| 144 | 'cmp' => \&three_way_cmp, | ||||||||||||||||||||||||||||
| 145 | 5 | ; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # CREATE/PARSE | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head2 new | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | $t = Image::Synchronize::Timestamp->new; | ||||||||||||||||||||||||||||
| 152 | $t = Image::Synchronize::Timestamp->new($value); | ||||||||||||||||||||||||||||
| 153 | $t2 = $t->new($value); | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Construct a new instance. If C<$value> is a number, then it is taken | ||||||||||||||||||||||||||||
| 156 | to represent the number of seconds since the epoch, in an undefined | ||||||||||||||||||||||||||||
| 157 | timezone. If C<$value> is defined but is not a number, then it is | ||||||||||||||||||||||||||||
| 158 | parsed as a timestamp in text format. See L</set_from_text> for | ||||||||||||||||||||||||||||
| 159 | details of the supported formats. | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | If C<$value> is specified but no timestamp can be extracted from it, | ||||||||||||||||||||||||||||
| 162 | then returns C<undef>. If C<$value> is not specified, then returns an | ||||||||||||||||||||||||||||
| 163 | empty instance that can be filled using L</set_from_text>. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 547 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 547 | my $invocant = shift; | |||||||||||||||||||||||||||
| 169 | 547 | ▶ | my $class = ref($invocant) || $invocant; # object or class name | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $invocant || $invocant
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant
$invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
| |||||||||||||||||||||||||||||
| 170 | 547 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 171 | 547 | ▶ | if ( scalar(@_) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 546 | $self->set_from_text($_[0]); | |||||||||||||||||||||||||||
| 173 | 546 | ▶ | return undef unless defined $self->{time}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | 541 | return $self; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =head2 clone | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | $t->clone; | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | Creates a clone of C<$t>. The clone is a "deep copy" so modifying any | ||||||||||||||||||||||||||||
| 183 | part of the clone does not affect any part of the original. | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | Calling C<clone> explicitly is useful if you need to modify the clone | ||||||||||||||||||||||||||||
| 186 | and want to leave the original unchanged. For example, | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | $t2 = $t->clone->set_timezone(0); # does not modify $t | ||||||||||||||||||||||||||||
| 189 | $t3 = $t->set_timezone(0); # modifies $t | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # no code; provided by package Clone | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # STRINGIFY | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =head2 stringify | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | $text = $t->stringify; | ||||||||||||||||||||||||||||
| 200 | $text = "$t"; | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | Returns a text version of C<$t>, in Exif format, i.e., using a colon | ||||||||||||||||||||||||||||
| 203 | C<:> as separator in the date, time, and timezone parts. Only the | ||||||||||||||||||||||||||||
| 204 | time part is always present, the date and timezone parts are only | ||||||||||||||||||||||||||||
| 205 | included when present. | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | The date part looks like C<'2000:01:02'>, showing year, month, and | ||||||||||||||||||||||||||||
| 208 | day. The time part looks like C<'03:04:05'>, showing hour, minute, | ||||||||||||||||||||||||||||
| 209 | and second. The timezone part looks like C<'+06:00'>, showing signed | ||||||||||||||||||||||||||||
| 210 | hour, minute, and (if it is not zero) seconds. The date and time part | ||||||||||||||||||||||||||||
| 211 | are separated by one space character. The time and timezone part are | ||||||||||||||||||||||||||||
| 212 | not separated. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | A full timestamp looks like C<'2000:01:02 03:04:05+06:00'>. This | ||||||||||||||||||||||||||||
| 215 | example is for a timezone where the clock time is 6 hours greater than | ||||||||||||||||||||||||||||
| 216 | UTC. | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | If C<$t> is empty (created via L</new> or L</set_from_text> with no | ||||||||||||||||||||||||||||
| 219 | argument), then C<< $t->stringify >> returns C<undef>, and C<"$t"> | ||||||||||||||||||||||||||||
| 220 | returns C<''>. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =cut | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 370 | ▶ | sub stringify { | ||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | 370 | my ($self) = @_; | |||||||||||||||||||||||||||
| 226 | 370 | ▶ | return unless defined $self->{time}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | return display_one_( $self->{time}, $self->{timezone_offset}, | ||||||||||||||||||||||||||||
| 228 | 370 | $self->{has_date}, ':', ' ' ); | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =head2 display_iso | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | $text = $t->display_iso; | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | Returns a text representation of the timestamp in ISO 8601 format, if | ||||||||||||||||||||||||||||
| 236 | the timestamp includes a date, for example | ||||||||||||||||||||||||||||
| 237 | C<2001-02-23T14:47:22+01:00> for a timestamp representing 14 hours 47 | ||||||||||||||||||||||||||||
| 238 | minutes 22 seconds (= 22 seconds past 2:47 pm) on February 23rd of the | ||||||||||||||||||||||||||||
| 239 | year 2001. | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | If the timestamp does not include a date, then returns the same as | ||||||||||||||||||||||||||||
| 242 | L</display_time>, of which the format is not part of ISO 8601. | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | Is like L</stringify> but uses a hyphen C<-> instead of a colon C<:> | ||||||||||||||||||||||||||||
| 245 | as separator in the date part, and uses a capital letter C<T> instead | ||||||||||||||||||||||||||||
| 246 | of a space as a separator between the date and time part. | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | If C<$t> is empty (created via L</new> or L</set_from_text> with no | ||||||||||||||||||||||||||||
| 249 | argument), then returns C<undef>. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =cut | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 140 | ▶ | sub display_iso { | ||||||||||||||||||||||||||
|
Subroutine
display_iso: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 254 | 140 | my ($self) = @_; | |||||||||||||||||||||||||||
| 255 | 140 | ▶ | return unless defined $self->{time}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | return display_one_( $self->{time}, $self->{timezone_offset}, | ||||||||||||||||||||||||||||
| 257 | 140 | $self->{has_date}, '-', 'T' ); | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =head2 display_utc | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | $text = $t->display_utc; | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | Returns a text version of C<$t>, in UTC in ISO 8601 format, if the | ||||||||||||||||||||||||||||
| 265 | timestamp includes a date. The returned text is like | ||||||||||||||||||||||||||||
| 266 | C<'2000-01-02T03:04:05Z'>, showing the year, month, day, hour, minute, | ||||||||||||||||||||||||||||
| 267 | and second. If C<$t> includes timezone information, then the text | ||||||||||||||||||||||||||||
| 268 | version represents the UTC date/time that represents the same instant | ||||||||||||||||||||||||||||
| 269 | of time as the original clock date/time in the specified timezone. If | ||||||||||||||||||||||||||||
| 270 | C<$t> has no timezone information then it is assumed to be in UTC | ||||||||||||||||||||||||||||
| 271 | already. | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | If the timestamp does not include a date, then returns the same as | ||||||||||||||||||||||||||||
| 274 | L</display_time>, of which the format is not part of ISO 8601. | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | Is like L</display_iso> but uses capital letter C<Z> for the timezone | ||||||||||||||||||||||||||||
| 277 | part. | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | If C<$t> is empty (created via L</new> or L</set_from_text> with no | ||||||||||||||||||||||||||||
| 280 | argument), then returns C<undef>. | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | Example: | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | $t = Image::Synchronize::Timestamp->new('2001-02-03 04:05:06+02:00'); | ||||||||||||||||||||||||||||
| 285 | $text = $t->display_utc; # '2001-02-03T02:05:06Z' | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =cut | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 4 | ▶ | sub display_utc { | ||||||||||||||||||||||||||
|
Subroutine
display_utc: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 290 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 291 | return unless (defined($self->{time}) | ||||||||||||||||||||||||||||
| 292 | 4 | ▶ | && defined($self->{timezone_offset})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"time"} and defined $self->{"timezone_offset"}
MC/DC50%1/2
defined $self->{"time"} and defined $self->{"timezone_offset"}
defined $self->{"time"}
defined $self->{"timezone_offset"}
Truth table66%2/3
A and B
A= defined $self->{"time"}B= defined $self->{"timezone_offset"}
| |||||||||||||||||||||||||||||
| 293 | 1 | my $t = $self->clone->adjust_to_utc; | |||||||||||||||||||||||||||
| 294 | 1 | return display_one_( $t->{time}, 'Z', $t->{has_date}, '-', 'T' ); | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | =head2 display_time | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | $text = $t->display_time | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | Returns a text version of C<$t> as a signed time value. The returned | ||||||||||||||||||||||||||||
| 302 | text is like C<'+03:04:05-06:07'>, showing the signed time (hour, | ||||||||||||||||||||||||||||
| 303 | minute, second) since the epoch in the associated timezone, followed | ||||||||||||||||||||||||||||
| 304 | by the designation of that timezone. The hour number is not | ||||||||||||||||||||||||||||
| 305 | restricted to be less than 24, and can be negative. The example is | ||||||||||||||||||||||||||||
| 306 | for a time that is 3 hours 4 minutes 5 seconds since the epoch in a | ||||||||||||||||||||||||||||
| 307 | timezone that is 6 hours and 7 minutes earlier than UTC. | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | This method is useful for timestamps without dates. If C<$t> was | ||||||||||||||||||||||||||||
| 310 | created with a date part, then the displayed number of hours is likely | ||||||||||||||||||||||||||||
| 311 | to be very large. | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | Examples: | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | $t = Image::Synchronize::Timestamp->new('01:02+03'); | ||||||||||||||||||||||||||||
| 316 | $text = $t->display_time; # '+01:02:00+03:00' | ||||||||||||||||||||||||||||
| 317 | $text = "$t"; # '1970:01:01 01:02:00+03:00' | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | $t = Image::Synchronize::Timestamp->new('2001-02-03T04:05'); | ||||||||||||||||||||||||||||
| 320 | $text = $t->display_time; # '+272548:05' | ||||||||||||||||||||||||||||
| 321 | # 272548 hours 5 minutes since epoch | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | =cut | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 74 | ▶ | sub display_time { | ||||||||||||||||||||||||||
|
Subroutine
display_time: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 326 | 74 | my ($self) = @_; | |||||||||||||||||||||||||||
| 327 | 74 | return display_tz_($self->time_local) . display_tz_($self->timezone_offset); | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | =head date | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | $text = $t->date; | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | Returns the date part of timestamp C<$t> in Exif format, similar to | ||||||||||||||||||||||||||||
| 335 | C<'2020:08:23'>. If C<$t> has a timezone offset, then the date part | ||||||||||||||||||||||||||||
| 336 | of a clone adjusted to UTC is returned. If C<$t> has no timezone | ||||||||||||||||||||||||||||
| 337 | offset, then the date part of the local time is returned. | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | =cut | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | ▶ | sub date { | ||||||||||||||||||||||||||
|
Subroutine
date: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 342 | 0 | my ($t) = @_; | |||||||||||||||||||||||||||
| 343 | 0 | ▶ | $t = $t->clone if $t->has_timezone_offset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 0 | return $t->stringify =~ s/ .*//r; | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | =head date | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | $text = $t->time; | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | Returns the time part of timestamp C<$t> in Exif format, similar to | ||||||||||||||||||||||||||||
| 352 | C<'11:21:53'>. If C<$t> has a timezone offset, then the time part of | ||||||||||||||||||||||||||||
| 353 | a clone adjusted to UTC is returned. If C<$t> has no timezone offset, | ||||||||||||||||||||||||||||
| 354 | then the time part of the local time is returned. | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | =cut | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 0 | ▶ | sub time { | ||||||||||||||||||||||||||
|
Subroutine
time: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 359 | 0 | my ($t) = @_; | |||||||||||||||||||||||||||
| 360 | 0 | ▶ | $t = $t->clone if $t->has_timezone_offset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 0 | return $t->stringify =~ s/^.*? //r; | |||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | # QUERY: | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | =head2 time_local | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | $seconds = $t->time_local; | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | Returns the number of non-leap seconds since the epoch in the timezone | ||||||||||||||||||||||||||||
| 371 | associated with the timestamp, or C<undef> if the timestamp is empty. | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | C<time_local> returns the same value for two timestamps with the same | ||||||||||||||||||||||||||||
| 374 | clock time but different timezone offsets. | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | Examples: | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | $t1 = Image::Synchronize::Timestamp->new('2001-02-03T04:05:06'); | ||||||||||||||||||||||||||||
| 379 | $t2 = $t1->clone->set_timezone(3600); # sets timezone to +01:00 | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | print $t1->time_local; # prints 981173106 | ||||||||||||||||||||||||||||
| 382 | print $t2->time_local; # prints the same | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | =cut | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 333 | ▶ | sub time_local { | ||||||||||||||||||||||||||
|
Subroutine
time_local: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 387 | 333 | my ($self) = @_; | |||||||||||||||||||||||||||
| 388 | 333 | return $self->{time}; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | =head2 time_utc | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | $seconds = $t->time_utc; | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | Returns the number of non-leap seconds since the epoch in UTC, or | ||||||||||||||||||||||||||||
| 396 | C<undef> if the timestamp is empty or has no timezone offset. | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | C<time_utc> returns different values for two timestamps with the same | ||||||||||||||||||||||||||||
| 399 | clock time but different timezone offsets. | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | Examples: | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | $t1 = Image::Synchronize::Timestamp->new('2001-02-03T04:05:06'); | ||||||||||||||||||||||||||||
| 404 | $t2 = $t1->clone->set_timezone_offset(3600); # timezone +01:00 | ||||||||||||||||||||||||||||
| 405 | $t3 = $t1->clone->set_timezone_offset(0); # timezone UTC = 00:00 | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | print $t1->time_utc; # undefined | ||||||||||||||||||||||||||||
| 408 | print $t2->time_utc; # 981169506 | ||||||||||||||||||||||||||||
| 409 | print $t3->time_utc; # 981173106 | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | =cut | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 160 | ▶ | sub time_utc { | ||||||||||||||||||||||||||
|
Subroutine
time_utc: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 414 | 160 | my ($self) = @_; | |||||||||||||||||||||||||||
| 415 | my $value = $self->{time} - $self->{timezone_offset} | ||||||||||||||||||||||||||||
| 416 | if defined( $self->{time} ) | ||||||||||||||||||||||||||||
| 417 | 160 | ▶ | and defined( $self->{timezone_offset} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"time"} and defined $self->{"timezone_offset"}
MC/DC50%1/2
defined $self->{"time"} and defined $self->{"timezone_offset"}
defined $self->{"time"}
defined $self->{"timezone_offset"}
Truth table66%2/3
A and B
A= defined $self->{"time"}B= defined $self->{"timezone_offset"}
| |||||||||||||||||||||||||||||
| 418 | 160 | return $value; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | =head2 timezone_offset | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | $seconds = $t->timezone_offset; | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | Returns the timezone offset from UTC in seconds, or C<undef> if no | ||||||||||||||||||||||||||||
| 427 | timezone offset is known. | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | =cut | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 212 | ▶ | sub timezone_offset { | ||||||||||||||||||||||||||
|
Subroutine
timezone_offset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 432 | 212 | my ($self) = @_; | |||||||||||||||||||||||||||
| 433 | 212 | return $self->{timezone_offset}; | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | =head2 local_timezone_offset | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | $seconds = $t->local_timezone_offset | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | Returns the difference between the local timezone and UTC, in seconds, | ||||||||||||||||||||||||||||
| 441 | for the instant of time represented by C<$t>. | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | If C<$t> has no timezone offset, then it is assumed to be in UTC. | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | The local timezone is the timezone that is valid at the specified time | ||||||||||||||||||||||||||||
| 446 | C<$t> for the system where the current process runs. | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | For example, if the process runs on a system that believes it is | ||||||||||||||||||||||||||||
| 449 | located in Amsterdam, then C<< $t->local_timezone_offset >> returns | ||||||||||||||||||||||||||||
| 450 | 3600 for dates/times C<$t> when standard time (UTC+1) is in effect in | ||||||||||||||||||||||||||||
| 451 | Amsterdam, and returns 7200 for dates/times C<$t> when daylight | ||||||||||||||||||||||||||||
| 452 | savings time (UTC+2) is in effect in Amsterdam. | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | =cut | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 2 | ▶ | sub local_timezone_offset { | ||||||||||||||||||||||||||
|
Subroutine
local_timezone_offset: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 457 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 458 | 2 | ▶ | my @t = localtime( $self->time_utc // $self->time_local ); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->time_utc // $self->time_local
MC/DC0%0/2
$self->time_utc // $self->time_local
$self->time_utc
$self->time_local
Truth table66%2/3
A // B
A= $self->time_utcB= $self->time_local
| |||||||||||||||||||||||||||||
| 459 | 2 | return timegm_modern(@t) - timelocal_modern(@t); | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | =head2 has_timezone_offset | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | $bool = $t->has_timezone_offset; | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | Returns a true value if timestamp C<$t> has a timezone offset, and a | ||||||||||||||||||||||||||||
| 467 | false value otherwise. | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | =cut | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 3 | ▶ | sub has_timezone_offset { | ||||||||||||||||||||||||||
|
Subroutine
has_timezone_offset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 472 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 473 | 3 | return defined $self->{timezone_offset}; | |||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | =head is_empty | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | $bool = $t->is_empty; | ||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | Returns a true value if the date/time part of C<$t> is not defined, | ||||||||||||||||||||||||||||
| 481 | and a false value otherwise. | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | =cut | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 2 | ▶ | sub is_empty { | ||||||||||||||||||||||||||
|
Subroutine
is_empty: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 486 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 487 | 2 | return not(defined $self->{time}); | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | =head has_date | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | $bool = $t->has_date; | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | Returns a true value if C<$t> has a date, and a false value otherwise. | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | =cut | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 1 | ▶ | sub has_date { | ||||||||||||||||||||||||||
|
Subroutine
has_date: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 499 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 500 | 1 | return $self->{has_date}; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | =head2 istypeof | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | $ok = Image::Synchronize::Timestamp->istypeof($item); | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | $t = Image::Synchronize::Timestamp->new('02:03'); | ||||||||||||||||||||||||||||
| 508 | $ok = $t->istypeof($item); # queries $item, not $t | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | Returns a true value if C<$item> is an instance of (a subclass of) | ||||||||||||||||||||||||||||
| 511 | Image::Synchronize::Timestamp, and a false value otherwise, including | ||||||||||||||||||||||||||||
| 512 | when C<$item> is not an object. | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | =cut | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | 1817 | ▶ | sub istypeof { | ||||||||||||||||||||||||||
|
Subroutine
istypeof: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 517 | 1817 | my $invocant = shift; | |||||||||||||||||||||||||||
| 518 | 1817 | ▶ | my $class = ref($invocant) || $invocant; # object or class name | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $invocant || $invocant
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant
$invocant
Truth table66%2/3
A || B
A= ref $invocantB= $invocant
| |||||||||||||||||||||||||||||
| 519 | 1817 | my ( $value ) = @_; | |||||||||||||||||||||||||||
| 520 | 1817 | ▶ | return blessed($value) && $value->isa($class); | ||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($value) && $value->isa($class)
MC/DC50%1/2
builtin::blessed($value) && $value->isa($class)
builtin::blessed($value)
$value->isa($class)
Truth table66%2/3
A && B
A= builtin::blessed($value)B= $value->isa($class)
| |||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | # COMBINE | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | =head2 + | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | # $t is an Image::Synchronize::Timestamp | ||||||||||||||||||||||||||||
| 528 | $sum = $t + $seconds; | ||||||||||||||||||||||||||||
| 529 | $sum = $seconds + $t; | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | Returns the timestamp that is C<$seconds> later than timestamp C<$t>. | ||||||||||||||||||||||||||||
| 532 | C<$seconds> must be a scalar number. | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | =cut | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 140 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 537 | 140 | my ( $self, $other, $swap ) = @_; | |||||||||||||||||||||||||||
| 538 | 140 | my $othertype = identify($other); | |||||||||||||||||||||||||||
| 539 | 140 | ▶ | if ( $othertype ne '-scalar-' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 540 | 2 | croak "Sorry, cannot add Image::Synchronize::Timestamp and $othertype"; | |||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | 138 | my $result = $self->clone; | |||||||||||||||||||||||||||
| 543 | 138 | $result->{time} += $other; | |||||||||||||||||||||||||||
| 544 | 138 | return $result; | |||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | =head2 - | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | # $t1, $t2 are Image::Synchronize::Timestamp | ||||||||||||||||||||||||||||
| 550 | $seconds = $t2 - $t1; # difference | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | $t3 = $t2 - $seconds; # shift | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | $t3 = -$t2; # negative | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | $t3 = $seconds - $t2; # shift negative | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | The first form returns the difference in seconds between the two | ||||||||||||||||||||||||||||
| 559 | timestamps C<$t2> and C<$t1>. If at least one of the two does not | ||||||||||||||||||||||||||||
| 560 | have a timezone offset, then both timestamps are assumed to be in the | ||||||||||||||||||||||||||||
| 561 | same timezone. If both have a timezone offset, then the difference | ||||||||||||||||||||||||||||
| 562 | between the timezone offsets is taken into account. | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | The second form shifts the timestamp back in time by the specified | ||||||||||||||||||||||||||||
| 565 | number of C<$seconds>, which must be a number. | ||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | The third form produces the opposite of the timestamp. The time part | ||||||||||||||||||||||||||||
| 568 | (the number of seconds since the epoch in the timezone) is multiplied | ||||||||||||||||||||||||||||
| 569 | by -1, but the timezone offset (if any) remains the same. This form | ||||||||||||||||||||||||||||
| 570 | is mostly useful if the timestamp has no date part. | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | The fourth form is equivalent to C<< $t3 = (-$t2) + $seconds >>: | ||||||||||||||||||||||||||||
| 573 | produce the negative of C<$t2> and then shift it to the future by the | ||||||||||||||||||||||||||||
| 574 | indicated number of C<$seconds>. | ||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | =cut | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 156 | ▶ | sub subtract { | ||||||||||||||||||||||||||
|
Subroutine
subtract: called CC=8 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 579 | 156 | my ( $self, $other, $swap ) = @_; | |||||||||||||||||||||||||||
| 580 | 156 | ▶ | if ( Image::Synchronize::Timestamp->istypeof($other) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 581 | return undef | ||||||||||||||||||||||||||||
| 582 | unless defined( $self->{time} ) | ||||||||||||||||||||||||||||
| 583 | 146 | ▶ | and defined( $other->{time} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"time"} and defined $other->{"time"}
MC/DC0%0/2
defined $self->{"time"} and defined $other->{"time"}
defined $self->{"time"}
defined $other->{"time"}
Truth table33%1/3
A and B
A= defined $self->{"time"}B= defined $other->{"time"}
| |||||||||||||||||||||||||||||
| 584 | 146 | my $difference = $self->{time} - $other->{time}; | |||||||||||||||||||||||||||
| 585 | 146 | ▶ | if ( defined( $self->{timezone_offset} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"timezone_offset"} and defined $other->{"timezone_offset"}
MC/DC50%1/2
defined $self->{"timezone_offset"} and defined $other->{"timezone_offset"}
defined $self->{"timezone_offset"}
defined $other->{"timezone_offset"}
Truth table66%2/3
A and B
A= defined $self->{"timezone_offset"}B= defined $other->{"timezone_offset"}
| |||||||||||||||||||||||||||||
| 586 | and defined( $other->{timezone_offset} ) ) | ||||||||||||||||||||||||||||
| 587 | { | ||||||||||||||||||||||||||||
| 588 | 103 | $difference += $other->{timezone_offset} - $self->{timezone_offset}; | |||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||
| 590 | 146 | ▶ | $difference = -$difference if $swap; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 591 | 146 | return $difference; | |||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||
| 593 | else { | ||||||||||||||||||||||||||||
| 594 | 10 | my $result = $self->clone; | |||||||||||||||||||||||||||
| 595 | 10 | $result->{time} -= $other; | |||||||||||||||||||||||||||
| 596 | 10 | ▶ | if ($swap) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 597 | 2 | $result->{time} = -$result->{time}; | |||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | 10 | return $result; | |||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | # COMPARE | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | =head2 <=> | ||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | $order = $t1 <=> $t2; | ||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | Returns -1, zero, or +1 depending on whether timestamp C<$t1> | ||||||||||||||||||||||||||||
| 610 | indicates an earlier, equal, or later instant of time than timestamp | ||||||||||||||||||||||||||||
| 611 | C<$t2>. If at least one of the two timestamps has no timezone, then | ||||||||||||||||||||||||||||
| 612 | both are assumed to be in the same timezone. The empty timestamp | ||||||||||||||||||||||||||||
| 613 | compares less than any defined timestamp, and compares equal to | ||||||||||||||||||||||||||||
| 614 | itself. | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | The following binary comparison operators are likewise available: | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | < <= == => > != | ||||||||||||||||||||||||||||
| 619 | cmp lt le eq ge gt ne | ||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | =cut | ||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | 545 | ▶ | sub three_way_cmp { | ||||||||||||||||||||||||||
|
Subroutine
three_way_cmp: called CC=10 SCAR=25.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 624 | 545 | my ( $self, $other, $swap ) = @_; | |||||||||||||||||||||||||||
| 625 | 545 | ▶ | croak "Found a " . identify($self) . ", need a " . __PACKAGE__ . "\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 626 | unless Image::Synchronize::Timestamp->istypeof($self); | ||||||||||||||||||||||||||||
| 627 | 545 | ▶ | unless ( Image::Synchronize::Timestamp->istypeof($other) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 628 | 13 | my $converted = Image::Synchronize::Timestamp->new($other); | |||||||||||||||||||||||||||
| 629 | 13 | ▶ | croak "Not a timestamp: $other\n" unless defined $converted; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 630 | 13 | $other = $converted; | |||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||
| 632 | 545 | my $result; | |||||||||||||||||||||||||||
| 633 | 545 | ▶ | if ( defined $self->{time} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 634 | 545 | ▶ | if ( defined $other->{time} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 635 | 545 | ▶ | if ( defined $self->{timezone_offset} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"timezone_offset"} and defined $other->{"timezone_offset"}
MC/DC100%2/2
defined $self->{"timezone_offset"} and defined $other->{"timezone_offset"}
defined $self->{"timezone_offset"}
defined $other->{"timezone_offset"}
Truth table100%3/3
A and B
A= defined $self->{"timezone_offset"}B= defined $other->{"timezone_offset"}
| |||||||||||||||||||||||||||||
| 636 | and defined $other->{timezone_offset} ) | ||||||||||||||||||||||||||||
| 637 | { | ||||||||||||||||||||||||||||
| 638 | $result = | ||||||||||||||||||||||||||||
| 639 | $self->{time} - | ||||||||||||||||||||||||||||
| 640 | $self->{timezone_offset} <=> $other->{time} - | ||||||||||||||||||||||||||||
| 641 | 347 | $other->{timezone_offset}; | |||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||
| 643 | else { | ||||||||||||||||||||||||||||
| 644 | 198 | $result = $self->{time} <=> $other->{time}; | |||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||
| 647 | else { | ||||||||||||||||||||||||||||
| 648 | 0 | $result = 1; # defined > undef | |||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||
| 651 | else { | ||||||||||||||||||||||||||||
| 652 | 0 | ▶ | if ( defined $other->{time} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 653 | 0 | $result = -1; # undef < defined | |||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | else { | ||||||||||||||||||||||||||||
| 656 | 0 | $result = 0; # undef == undef | |||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||
| 659 | 545 | ▶ | $result = -$result if $swap; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 660 | 545 | return $result; | |||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | =head2 identical | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | $bool = $t1->identical($t2); | ||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||
| 667 | Returns a true value if the two timestamps are identical, and a false | ||||||||||||||||||||||||||||
| 668 | value otherwise. The two timestamps are identical if the date/time | ||||||||||||||||||||||||||||
| 669 | part and the timezone offset part are identical in both. This method | ||||||||||||||||||||||||||||
| 670 | returns false for two timestamps that indicate the same instant of | ||||||||||||||||||||||||||||
| 671 | time but have different timezone parts. | ||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | =cut | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | 121 | ▶ | sub identical { | ||||||||||||||||||||||||||
|
Subroutine
identical: called CC=7 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||
| 676 | 121 | my ( $self, $other, $swap ) = @_; | |||||||||||||||||||||||||||
| 677 | 121 | ▶ | return if defined( $self->{time} ) != defined( $other->{time} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 678 | return | ||||||||||||||||||||||||||||
| 679 | if defined( $self->{timezone_offset} ) != | ||||||||||||||||||||||||||||
| 680 | 121 | ▶ | defined( $other->{timezone_offset} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||
| 682 | # now each of the components either is defined in both objects or is | ||||||||||||||||||||||||||||
| 683 | # not defined in both objects | ||||||||||||||||||||||||||||
| 684 | 119 | ▶ | if ( defined $self->{time} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 685 | 119 | ▶ | if ( defined $self->{timezone_offset} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 686 | return ( $self->{time} == $other->{time} | ||||||||||||||||||||||||||||
| 687 | 24 | ▶ | && $self->{timezone_offset} == $other->{timezone_offset} ); | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->{'time'} == $other->{'time'} && $self->{'timezone_offset'} == $other->{'timezone_offset'}
MC/DC100%2/2
$self->{'time'} == $other->{'time'} && $self->{'timezone_offset'} == $other->{'timezone_offset'}
$self->{'time'} == $other->{'time'}
$self->{'timezone_offset'} == $other->{'timezone_offset'}
Truth table100%3/3
A && B
A= $self->{'time'} == $other->{'time'}B= $self->{'timezone_offset'} == $other->{'timezone_offset'}
| |||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||
| 689 | else { | ||||||||||||||||||||||||||||
| 690 | 95 | return $self->{time} == $other->{time}; | |||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||
| 693 | else { | ||||||||||||||||||||||||||||
| 694 | 0 | ▶ | if ( defined $self->{timezone_offset} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 695 | 0 | return $self->{timezone_offset} == $other->{timezone_offset}; | |||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||
| 697 | else { | ||||||||||||||||||||||||||||
| 698 | 0 | return 1; | |||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | # MODIFY | ||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||
| 705 | =head2 set_from_text | ||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | $t->set_from_text($text); | ||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||
| 709 | Sets C<$t> to the instant of time expressed by text C<$text>, | ||||||||||||||||||||||||||||
| 710 | discarding any previous contents of C<$t>. | ||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | The text must specify at least a time, and optionally also a date and | ||||||||||||||||||||||||||||
| 713 | a timezone offset. | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | The date must consist of three numbers (year, month, day) separated by | ||||||||||||||||||||||||||||
| 716 | either a colon C<:> or a dash C<->. The time must consist of from one | ||||||||||||||||||||||||||||
| 717 | to three numbers (hour, minute, second) separated by a colon C<:>. | ||||||||||||||||||||||||||||
| 718 | The date and time must be separated by a single whitespace or a | ||||||||||||||||||||||||||||
| 719 | capital T. | ||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | An offset from UTC may be specified, as from one to three numbers, of | ||||||||||||||||||||||||||||
| 722 | which the first one must be signed and represents hours, and the | ||||||||||||||||||||||||||||
| 723 | remaining ones (if specified) must be separated from the previous by a | ||||||||||||||||||||||||||||
| 724 | colon C<:>, and represent minutes and seconds. | ||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | These formats include the format of Exif timestamps, for example | ||||||||||||||||||||||||||||
| 727 | C<'2010:06:27 17:44:12+03:00:00'> or C<'2010:06:27 17:50:00'>, and | ||||||||||||||||||||||||||||
| 728 | also the ISO 8601 formats C<'2010-06-27T17:44:12+03:00'> or | ||||||||||||||||||||||||||||
| 729 | C<'2010-06-27T17:50:00'>. | ||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | The example timestamps with timezone offset represent June 27th of the | ||||||||||||||||||||||||||||
| 732 | year 2010, at 44 minutes and 12 seconds past 5 o'clock in the | ||||||||||||||||||||||||||||
| 733 | afternoon, in a timezone where the clock reads 3 hours later than UTC. | ||||||||||||||||||||||||||||
| 734 | The corresponding UTC time is 14:44:12. | ||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||
| 736 | If the text cannot be parsed as a timestamp, then the | ||||||||||||||||||||||||||||
| 737 | C<Image::Synchronize::Timestamp> is left without contents. | ||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | Returns C<$t>. | ||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||
| 741 | =cut | ||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||
| 743 | 548 | ▶ | sub set_from_text { | ||||||||||||||||||||||||||
|
Subroutine
set_from_text: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 744 | 548 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 745 | 548 | my ( $time, $offset, $has_date ); | |||||||||||||||||||||||||||
| 746 | 548 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 747 | 547 | ▶ | if ( $value =~ /^[-+]?\d+$/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 748 | { | ||||||||||||||||||||||||||||
| 749 | 94 | $time = $value; | |||||||||||||||||||||||||||
| 750 | 94 | $has_date = 1; | |||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||
| 752 | else { | ||||||||||||||||||||||||||||
| 753 | 453 | ( $time, $offset, $has_date ) = parse_( $value ); | |||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||
| 756 | 548 | delete $self->{$_} foreach qw(time timezone_offset has_date); | |||||||||||||||||||||||||||
| 757 | 548 | ▶ | $self->{time} = $time if defined $time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 758 | 548 | ▶ | $self->{timezone_offset} = $offset if defined $offset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 759 | 548 | ▶ | $self->{has_date} = $has_date if defined $has_date; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 760 | 548 | return $self; | |||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||
| 764 | =head2 adjust_timezone_offset | ||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||
| 766 | $t->adjust_timezone_offset($offset); | ||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||
| 768 | Adjusts the timezone offset of C<$t> to <$offset>, if C<$t> is not | ||||||||||||||||||||||||||||
| 769 | empty. | ||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||
| 771 | If C<$t> already had a timezone offset, then its clock time is | ||||||||||||||||||||||||||||
| 772 | adjusted so it refers to the same instant of time as before, but now | ||||||||||||||||||||||||||||
| 773 | relative to the new timezone. | ||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||
| 775 | If C<$offset> is C<undef>, then the timezone of C<$t> becomes | ||||||||||||||||||||||||||||
| 776 | undefined. | ||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||
| 778 | Returns the object. | ||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||
| 780 | =cut | ||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||
| 782 | 83 | ▶ | sub adjust_timezone_offset { | ||||||||||||||||||||||||||
|
Subroutine
adjust_timezone_offset: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 783 | 83 | my ( $self, $offset ) = @_; | |||||||||||||||||||||||||||
| 784 | 83 | ▶ | if ( defined $offset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 785 | 73 | ▶ | if ( defined $self->{timezone_offset} ) { # already have a timezone | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 786 | 32 | $self->{time} += $offset - $self->{timezone_offset}; | |||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||
| 788 | 73 | $self->{timezone_offset} = $offset; | |||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||
| 790 | else { | ||||||||||||||||||||||||||||
| 791 | 10 | delete $self->{timezone_offset}; | |||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||
| 793 | 83 | $self; | |||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||
| 796 | =head2 adjust_to_local_timezone | ||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||
| 798 | $t->adjust_to_local_timezone | ||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||
| 800 | Adjusts the timezone of timestamp C<$t> to the local timezone | ||||||||||||||||||||||||||||
| 801 | appropriate for the local system at the indicated instant of time. | ||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||
| 803 | If C<$t> already had a timezone offset, then adjusts the clock time so | ||||||||||||||||||||||||||||
| 804 | it refers to the same instant of time as before but now relative to | ||||||||||||||||||||||||||||
| 805 | the local timezone. | ||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||
| 807 | Returns the adjusted C<$t>. | ||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||
| 809 | =cut | ||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||
| 811 | 1 | ▶ | sub adjust_to_local_timezone { | ||||||||||||||||||||||||||
|
Subroutine
adjust_to_local_timezone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 812 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 813 | 1 | $self->adjust_timezone_offset( $self->local_timezone_offset ); | |||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||
| 816 | =head2 adjust_to_utc | ||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||
| 818 | $t->adjust_to_utc | ||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | Adjusts the timezone of timestamp C<$t> to UTC, if C<$t> is not an | ||||||||||||||||||||||||||||
| 821 | empty timestamp. | ||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||
| 823 | If C<$t> already had a timezone offset, then adjusts the clock time so | ||||||||||||||||||||||||||||
| 824 | it refers to the same instant of time as before but now relative to | ||||||||||||||||||||||||||||
| 825 | UTC. | ||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||
| 827 | Returns the adjusted C<$t>. | ||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||
| 829 | =cut | ||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||
| 831 | 2 | ▶ | sub adjust_to_utc { | ||||||||||||||||||||||||||
|
Subroutine
adjust_to_utc: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 832 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 833 | 2 | ▶ | $self->adjust_timezone_offset(0) if defined $self->{time}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||
| 836 | =head2 set_timezone_offset | ||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||
| 838 | $t->set_timezone_offset($offset); | ||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||
| 840 | Sets the timezone offset of C<$t> to <$offset>, discarding the | ||||||||||||||||||||||||||||
| 841 | previous timezone offset if any. The clock time is not adjusted. | ||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||
| 843 | If C<$offset> is C<undef>, then the timezone of C<$t> becomes | ||||||||||||||||||||||||||||
| 844 | undefined. | ||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||
| 846 | Returns the object. | ||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||
| 848 | =cut | ||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | 3 | ▶ | sub set_timezone_offset { | ||||||||||||||||||||||||||
|
Subroutine
set_timezone_offset: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 851 | 3 | my ( $self, $offset ) = @_; | |||||||||||||||||||||||||||
| 852 | 3 | ▶ | if ( defined $offset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 853 | 3 | $self->{timezone_offset} = $offset; | |||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||
| 855 | else { | ||||||||||||||||||||||||||||
| 856 | 0 | delete $self->{timezone_offset}; | |||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||
| 858 | 3 | $self; | |||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||
| 862 | =head2 remove_timezone | ||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||
| 864 | $t->remove_timezone | ||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||
| 866 | Removes the timezone offset from timestamp C<$t>. The clock time | ||||||||||||||||||||||||||||
| 867 | remains the same. | ||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||
| 869 | Returns the modified C<$t>. | ||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||
| 871 | =cut | ||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||
| 873 | 70 | ▶ | sub remove_timezone { | ||||||||||||||||||||||||||
|
Subroutine
remove_timezone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 874 | 70 | my ($self) = @_; | |||||||||||||||||||||||||||
| 875 | 70 | delete $self->{timezone_offset}; | |||||||||||||||||||||||||||
| 876 | 70 | return $self; | |||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | =head2 adjust_nodate | ||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||
| 881 | $t->adjust_nodate; | ||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||
| 883 | If timestamp C<$t> has a date, then remove that date by changing C<$t> | ||||||||||||||||||||||||||||
| 884 | to the no-date form. The offset from the epoch in seconds is instead | ||||||||||||||||||||||||||||
| 885 | interpreted as an offset from an unspecified zero point that is not | ||||||||||||||||||||||||||||
| 886 | associated with a particular date. | ||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||
| 888 | A timestamp with no date gets stringified to an optionally signed | ||||||||||||||||||||||||||||
| 889 | timestamp consisting of hours, minutes, and seconds, optionally with a | ||||||||||||||||||||||||||||
| 890 | timezone offset. The number of hours in the timestamp may be much | ||||||||||||||||||||||||||||
| 891 | greater than 24. | ||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||
| 893 | =cut | ||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||
| 895 | 43 | ▶ | sub adjust_nodate { | ||||||||||||||||||||||||||
|
Subroutine
adjust_nodate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 896 | 43 | my ($self) = @_; | |||||||||||||||||||||||||||
| 897 | 43 | delete $self->{has_date}; | |||||||||||||||||||||||||||
| 898 | 43 | return $self; | |||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||
| 901 | =head2 adjust_todate | ||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||
| 903 | $t->adjust_todate; | ||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||
| 905 | If timestamp C<$t> has no date, then add a date by changing C<$t> to | ||||||||||||||||||||||||||||
| 906 | the with-date form. The offset from an unspecified zero point not | ||||||||||||||||||||||||||||
| 907 | associated with any particular date is instead interpreted as the | ||||||||||||||||||||||||||||
| 908 | offset from the epoch. | ||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||
| 910 | =cut | ||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||
| 912 | 0 | ▶ | sub adjust_todate { | ||||||||||||||||||||||||||
|
Subroutine
adjust_todate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 913 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 914 | 0 | $self->{has_date} = 1; | |||||||||||||||||||||||||||
| 915 | 0 | return $self; | |||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||
| 918 | # Private helper functions, not part of the official interface | ||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||
| 920 | 452 | ▶ | sub parse_components_ { | ||||||||||||||||||||||||||
|
Subroutine
parse_components_: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 921 | 452 | my ($text) = @_; | |||||||||||||||||||||||||||
| 922 | 452 | ▶ | return unless $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||
| 924 | # process date and time and timezone | ||||||||||||||||||||||||||||
| 925 | # Date = Y-M-D or Y:M:D | ||||||||||||||||||||||||||||
| 926 | # Time = H:M:S or H:M or H | ||||||||||||||||||||||||||||
| 927 | # Timezone = Z or -H or +H or -H:M or +H:M or -H:M:S or +H:M:S | ||||||||||||||||||||||||||||
| 928 | # S = space or T | ||||||||||||||||||||||||||||
| 929 | # complete = DateSTimeTimezone | ||||||||||||||||||||||||||||
| 930 | # or DateSTime | ||||||||||||||||||||||||||||
| 931 | # or TimeTimezone | ||||||||||||||||||||||||||||
| 932 | # or SignTimeTimezone | ||||||||||||||||||||||||||||
| 933 | 452 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 934 | $text =~ /^ | ||||||||||||||||||||||||||||
| 935 | (?: # start date + hour or signed hour | ||||||||||||||||||||||||||||
| 936 | (?: # start date + hour | ||||||||||||||||||||||||||||
| 937 | (?: # start date | ||||||||||||||||||||||||||||
| 938 | (?<year>\d+) | ||||||||||||||||||||||||||||
| 939 | ([-:]) | ||||||||||||||||||||||||||||
| 940 | (?<month>\d+) | ||||||||||||||||||||||||||||
| 941 | \g{-2} # same separator as for year - month | ||||||||||||||||||||||||||||
| 942 | (?<day>\d+) | ||||||||||||||||||||||||||||
| 943 | [ T] # separator is space or T | ||||||||||||||||||||||||||||
| 944 | ) # end date | ||||||||||||||||||||||||||||
| 945 | (?<hour>\d+) | ||||||||||||||||||||||||||||
| 946 | ) # end date + hour | ||||||||||||||||||||||||||||
| 947 | | | ||||||||||||||||||||||||||||
| 948 | (?: # start optionaly signed hour | ||||||||||||||||||||||||||||
| 949 | (?<hoursign>[-+])? # sign is optional | ||||||||||||||||||||||||||||
| 950 | (?<hour>\d+) | ||||||||||||||||||||||||||||
| 951 | ) # end optionally signed hour | ||||||||||||||||||||||||||||
| 952 | ) # end date + hour or signed hour | ||||||||||||||||||||||||||||
| 953 | (?: | ||||||||||||||||||||||||||||
| 954 | : # separator hour - minute | ||||||||||||||||||||||||||||
| 955 | (?<minute>\d+) | ||||||||||||||||||||||||||||
| 956 | )? # minute is optional | ||||||||||||||||||||||||||||
| 957 | (?: | ||||||||||||||||||||||||||||
| 958 | : # separator minute - second | ||||||||||||||||||||||||||||
| 959 | (?<second>\d+(?:\.\d+)?) # second may have fractional part | ||||||||||||||||||||||||||||
| 960 | )? # second is optional | ||||||||||||||||||||||||||||
| 961 | (?: # start timezone | ||||||||||||||||||||||||||||
| 962 | (?<tzutc>Z) # Z means UTC | ||||||||||||||||||||||||||||
| 963 | | | ||||||||||||||||||||||||||||
| 964 | (?: # start numeric timezone | ||||||||||||||||||||||||||||
| 965 | (?<tzsign>[-+]) # sign is required | ||||||||||||||||||||||||||||
| 966 | (?<tzhour>\d+) | ||||||||||||||||||||||||||||
| 967 | (?: # start timezone minute | ||||||||||||||||||||||||||||
| 968 | : # separator hour - minute | ||||||||||||||||||||||||||||
| 969 | (?<tzminute>\d+) | ||||||||||||||||||||||||||||
| 970 | )? # minute is optional | ||||||||||||||||||||||||||||
| 971 | (?: | ||||||||||||||||||||||||||||
| 972 | : # separator timezone minute - second | ||||||||||||||||||||||||||||
| 973 | (?<tzsecond>\d+(?:\.\d+)?) | ||||||||||||||||||||||||||||
| 974 | )? # second is optional | ||||||||||||||||||||||||||||
| 975 | ) # end numeric timezone | ||||||||||||||||||||||||||||
| 976 | )? # end timezone, timezone is optional | ||||||||||||||||||||||||||||
| 977 | $/x | ||||||||||||||||||||||||||||
| 978 | ) | ||||||||||||||||||||||||||||
| 979 | { # timezone | ||||||||||||||||||||||||||||
| 980 | 448 | my $offset; | |||||||||||||||||||||||||||
| 981 | 448 | ▶ | if ( $+{tzutc} ) { # timezone is UTC | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 982 | 8 | $offset = 0; | |||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||
| 984 | elsif ( $+{tzsign} ) { | ||||||||||||||||||||||||||||
| 985 | 107 | $offset = $+{tzhour} * 3600; | |||||||||||||||||||||||||||
| 986 | 107 | ▶ | $offset += $+{tzminute} * 60 if $+{tzminute}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 987 | 107 | ▶ | $offset += $+{tzsecond} if $+{tzsecond}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 988 | 107 | ▶ | $offset = -$offset if $+{tzsign} eq '-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||
| 990 | 3136 | ▶ | my @c = map { defined($_) ? 1 * $_ : $_ } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 991 | ( | ||||||||||||||||||||||||||||
| 992 | $+{year}, $+{month}, $+{day}, | ||||||||||||||||||||||||||||
| 993 | $+{hour}, $+{minute}, $+{second}, | ||||||||||||||||||||||||||||
| 994 | 448 | $offset | |||||||||||||||||||||||||||
| 995 | ); | ||||||||||||||||||||||||||||
| 996 | 448 | ▶ | if (defined($+{hoursign}) && $+{hoursign} eq '-') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $+{"hoursign"} and $+{"hoursign"} eq "-"
MC/DC100%2/2
defined $+{"hoursign"} and $+{"hoursign"} eq "-"
defined $+{"hoursign"}
$+{"hoursign"} eq "-"
Truth table100%3/3
A and B
A= defined $+{"hoursign"}B= $+{"hoursign"} eq "-"
| |||||||||||||||||||||||||||||
| 997 | 42 | foreach my $i (qw(3 4 5)) { | |||||||||||||||||||||||||||
| 998 | 126 | ▶ | if (defined $c[$i]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 999 | 126 | $c[$i] *= -1; | |||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||
| 1001 | } | ||||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||
| 1003 | 448 | return @c; | |||||||||||||||||||||||||||
| 1004 | } | ||||||||||||||||||||||||||||
| 1005 | else { | ||||||||||||||||||||||||||||
| 1006 | 4 | return (); | |||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||
| 1010 | 448 | ▶ | sub components_to_time_and_offset_ { | ||||||||||||||||||||||||||
|
Subroutine
components_to_time_and_offset_: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1011 | 448 | my @components = @_; | |||||||||||||||||||||||||||
| 1012 | 448 | ▶ | $components[$_] //= 0 foreach 3 .. 5; # hours .. seconds | ||||||||||||||||||||||||||
|
Condition100%2/2
$components[$_] //= 0
MC/DC100%1/1
$components[$_] //= 0
$components[$_]
Truth table100%2/2
A
A= $components[$_]
| |||||||||||||||||||||||||||||
| 1013 | 448 | my ($time, $has_date); | |||||||||||||||||||||||||||
| 1014 | 448 | ▶ | if (defined $components[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1015 | # have year-month-day too | ||||||||||||||||||||||||||||
| 1016 | 298 | eval { | |||||||||||||||||||||||||||
| 1017 | 298 | $time = timegm_modern( | |||||||||||||||||||||||||||
| 1018 | $components[5], $components[4], $components[3], | ||||||||||||||||||||||||||||
| 1019 | $components[2], $components[1] - 1, | ||||||||||||||||||||||||||||
| 1020 | $components[0] | ||||||||||||||||||||||||||||
| 1021 | ); | ||||||||||||||||||||||||||||
| 1022 | }; | ||||||||||||||||||||||||||||
| 1023 | 298 | ▶ | return if $@; # unparseable time | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1024 | 298 | $has_date = 1; | |||||||||||||||||||||||||||
| 1025 | } else { | ||||||||||||||||||||||||||||
| 1026 | 150 | $time = $components[3]*3600 + $components[4]*60 + $components[5]; | |||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||
| 1028 | 448 | return ( $time, $components[6], $has_date ); | |||||||||||||||||||||||||||
| 1029 | } | ||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||
| 1031 | # a private sub to parse a timestamp | ||||||||||||||||||||||||||||
| 1032 | 453 | ▶ | sub parse_ { | ||||||||||||||||||||||||||
|
Subroutine
parse_: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1033 | 453 | my ($text) = @_; | |||||||||||||||||||||||||||
| 1034 | 453 | ▶ | return unless $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1035 | 452 | my @components = parse_components_($text); | |||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||
| 1037 | # components: | ||||||||||||||||||||||||||||
| 1038 | # 0 1 2 3 4 5 6 | ||||||||||||||||||||||||||||
| 1039 | # (year, month, day, hour, minute, second, offset) | ||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||
| 1041 | # must have at least the hour | ||||||||||||||||||||||||||||
| 1042 | 452 | ▶ | return unless defined $components[3]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1043 | 448 | return components_to_time_and_offset_(@components); | |||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||
| 1046 | 450 | ▶ | sub display_tz_ { | ||||||||||||||||||||||||||
|
Subroutine
display_tz_: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1047 | 450 | my ($offset) = @_; | |||||||||||||||||||||||||||
| 1048 | 450 | my $tz = ''; | |||||||||||||||||||||||||||
| 1049 | 450 | ▶ | if ( defined $offset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1050 | 350 | ▶ | if (Image::Synchronize::Timestamp->istypeof($offset)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1051 | 0 | ▶ | if ($offset->has_date) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1052 | 0 | $offset = $offset->clone->adjust_nodate; | |||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||
| 1054 | 0 | return "$offset"; | |||||||||||||||||||||||||||
| 1055 | } else { | ||||||||||||||||||||||||||||
| 1056 | 5 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||
| 1058 | 350 | ▶ | my $sign = ($offset < 0)? '-': '+'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1059 | 350 | $offset = abs($offset); | |||||||||||||||||||||||||||
| 1060 | 350 | my $tzhour = $offset / 3600; | |||||||||||||||||||||||||||
| 1061 | 350 | $offset -= 3600 * $tzhour; | |||||||||||||||||||||||||||
| 1062 | 350 | my $tzmin = $offset / 60; | |||||||||||||||||||||||||||
| 1063 | 350 | $offset -= 60 * $tzmin; | |||||||||||||||||||||||||||
| 1064 | 350 | ▶ | if ($offset) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1065 | 79 | $tz = $sign . sprintf( '%02d:%02d:%02d', $tzhour, $tzmin, $offset ); | |||||||||||||||||||||||||||
| 1066 | } else { | ||||||||||||||||||||||||||||
| 1067 | 271 | $tz = $sign . sprintf( '%02d:%02d', $tzhour, $tzmin ); | |||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||
| 1070 | } | ||||||||||||||||||||||||||||
| 1071 | 450 | return $tz; | |||||||||||||||||||||||||||
| 1072 | } | ||||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||
| 1074 | 511 | ▶ | sub display_one_ { | ||||||||||||||||||||||||||
|
Subroutine
display_one_: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1075 | 511 | my ( $time, $offset, $has_date, $date_separator, | |||||||||||||||||||||||||||
| 1076 | $date_time_separator ) = @_; | ||||||||||||||||||||||||||||
| 1077 | 511 | ▶ | return unless defined $time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1078 | 511 | ▶ | if ($has_date) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1079 | 483 | my ( $sec, $min, $hour, $mday, $mon, $year ) = gmtime($time); | |||||||||||||||||||||||||||
| 1080 | 483 | my $tz = ''; | |||||||||||||||||||||||||||
| 1081 | 483 | ▶ | if (defined $offset) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1082 | 247 | ▶ | if ($offset eq 'Z') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1083 | 1 | $tz = 'Z'; | |||||||||||||||||||||||||||
| 1084 | } else { | ||||||||||||||||||||||||||||
| 1085 | 246 | $tz = display_tz_($offset); | |||||||||||||||||||||||||||
| 1086 | } | ||||||||||||||||||||||||||||
| 1087 | } | ||||||||||||||||||||||||||||
| 1088 | 483 | my $format = '%d' | |||||||||||||||||||||||||||
| 1089 | . $date_separator . '%02d' | ||||||||||||||||||||||||||||
| 1090 | . $date_separator . '%02d' | ||||||||||||||||||||||||||||
| 1091 | . $date_time_separator | ||||||||||||||||||||||||||||
| 1092 | . '%02d:%02d:%02d'; | ||||||||||||||||||||||||||||
| 1093 | return | ||||||||||||||||||||||||||||
| 1094 | 483 | sprintf( $format, $year + 1900, $mon + 1, $mday, $hour, $min, $sec ) | |||||||||||||||||||||||||||
| 1095 | . $tz; | ||||||||||||||||||||||||||||
| 1096 | } else { | ||||||||||||||||||||||||||||
| 1097 | 28 | return display_tz_($time) . display_tz_($offset); | |||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||
| 1101 | 0 | ▶ | sub display_utc_one_ { | ||||||||||||||||||||||||||
|
Subroutine
display_utc_one_: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1102 | 0 | my ($time) = @_; | |||||||||||||||||||||||||||
| 1103 | 0 | ▶ | return unless defined $time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1104 | 0 | my ( $sec, $min, $hour, $mday, $mon, $year ) = gmtime($time); | |||||||||||||||||||||||||||
| 1105 | 0 | return sprintf( | |||||||||||||||||||||||||||
| 1106 | '%d-%02d-%02dT%02d:%02d:%02dZ', | ||||||||||||||||||||||||||||
| 1107 | $year + 1900, | ||||||||||||||||||||||||||||
| 1108 | $mon + 1, $mday, $hour, $min, $sec | ||||||||||||||||||||||||||||
| 1109 | ); | ||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||
| 1112 | # identify the type of the value in a non-empty string, either the | ||||||||||||||||||||||||||||
| 1113 | # name of the package (if an object), or the reference type (if a | ||||||||||||||||||||||||||||
| 1114 | # reference), or '-undef-' (if undef), or '-scalar-'. | ||||||||||||||||||||||||||||
| 1115 | 140 | ▶ | sub identify { | ||||||||||||||||||||||||||
|
Subroutine
identify: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1116 | 140 | my ($value) = @_; | |||||||||||||||||||||||||||
| 1117 | 140 | ▶ | if ( ref $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1118 | 2 | ▶ | return ( blessed($value) or ref($value) ); | ||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($value) || ref $value
MC/DC0%0/2
builtin::blessed($value) || ref $value
builtin::blessed($value)
ref $value
Truth table33%1/3
A || B
A= builtin::blessed($value)B= ref $value
| |||||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||
| 1120 | 138 | ▶ | return defined($value)? '-scalar-': '-undef-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1121 | } | ||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||
| 1123 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||
| 1125 | Louis Strous E<lt>LS@quae.nlE<gt> | ||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||
| 1127 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||
| 1129 | Copyright (c) 2016-2020 Louis Strous. | ||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||
| 1131 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 1132 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||
| 1134 | =cut | ||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||
| 1136 | 5 | 1; | |||||||||||||||||||||||||||