| 1 | package DateTime::Format::GeekTime; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use 5.005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | $VERSION='1.001'; | |||||||||||||||||||||||||||
| 10 | 3 | $VERSION=eval $VERSION; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 1 | my ($class,$year)=@_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | if (!defined $year) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 0 | $year = DateTime->now->year; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | return bless {year=>$year},$class; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 11 | ▶ | sub parse_datetime { | ||||||||||||||||||||||||||
|
Subroutine
parse_datetime: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 11 | my ($self,$string)=@_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 11 | my ($seconds,$days) = | |||||||||||||||||||||||||||
| 26 | ($string =~ m{\A \s* | ||||||||||||||||||||||||||||
| 27 | (?:0x)? ( [0-9a-fA-F]{4} ) | ||||||||||||||||||||||||||||
| 28 | (?: [\w\s]*? ) | ||||||||||||||||||||||||||||
| 29 | (?:0x)? ( [0-9a-fA-F]{3,4} ) | ||||||||||||||||||||||||||||
| 30 | (?: \s+ .)? # optional character representation | ||||||||||||||||||||||||||||
| 31 | \s* \z}smx); | ||||||||||||||||||||||||||||
| 32 | 11 | ▶ | if (!(defined $seconds and defined $days)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $seconds and defined $days
MC/DC0%0/2
defined $seconds and defined $days
defined $seconds
defined $days
Truth table33%1/3
A and B
A= defined $secondsB= defined $days
| |||||||||||||||||||||||||||||
| 33 | 0 | croak "<$string> is not a proper GeekTime string"; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 11 | $seconds=hex($seconds);$days=hex($days); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 11 | $seconds=int($seconds*86_400/65_536+0.5); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 11 | my $base_year; | |||||||||||||||||||||||||||
| 41 | 11 | ▶ | if (ref($self)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 10 | $base_year=$self->{year}; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | 1 | $base_year=DateTime->now->year; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 11 | my $dt=DateTime->new(year=>$base_year,time_zone=>'UTC'); | |||||||||||||||||||||||||||
| 49 | 11 | $dt->add(days=>$days,seconds=>$seconds); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 11 | return $dt; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub format_datetime { | ||||||||||||||||||||||||||
|
Subroutine
format_datetime: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 2 | my ($self,$dt)=@_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | my $start_of_day=$dt->clone->set_time_zone('UTC')->truncate(to=>'day'); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | my $seconds=$dt->subtract_datetime_absolute($start_of_day)->in_units('seconds'); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | my $days=$dt->day_of_year - 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | $seconds=int($seconds/86_400*65_536+0.5); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | my $chr = $seconds <= 0xD800 || $seconds >= 0xDFFF | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$seconds <= 55296 or $seconds >= 57343
MC/DC50%1/2
$seconds <= 55296 or $seconds >= 57343
$seconds <= 55296
$seconds >= 57343
Truth table66%2/3
A or B
A= $seconds <= 55296B= $seconds >= 57343
| |||||||||||||||||||||||||||||
| 66 | ? ' '.chr($seconds) | ||||||||||||||||||||||||||||
| 67 | : ''; | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | return sprintf '0x%04X on day 0x%03X%s',$seconds,$days,$chr; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | 1; | |||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||