| 1 | #! /bin/false | ||||||||||||
| 2 | |||||||||||||
| 3 | # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>, | ||||||||||||
| 4 | # all rights reserved. | ||||||||||||
| 5 | |||||||||||||
| 6 | # This program is free software: you can redistribute it and/or modify | ||||||||||||
| 7 | # it under the terms of the GNU General Public License as published by | ||||||||||||
| 8 | # the Free Software Foundation; either version 3 of the License, or | ||||||||||||
| 9 | # (at your option) any later version. | ||||||||||||
| 10 | |||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||
| 14 | # GNU General Public License for more details. | ||||||||||||
| 15 | |||||||||||||
| 16 | # You should have received a copy of the GNU General Public License | ||||||||||||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||
| 18 | |||||||||||||
| 19 | package Qgoda::Util::Date; | ||||||||||||
| 20 | 6 | $Qgoda::Util::Date::VERSION = 'v0.9.2'; | |||||||||||
| 21 | 6 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | |||||||||||||
| 23 | 6 | ▶ | use Date::Parse qw(str2time); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 6 | ▶ | use POSIX qw(strftime); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 6 | ▶ | use Locale::TextDomain qw('qgoda'); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | |||||||||||||
| 27 | use overload | ||||||||||||
| 28 | 6 | '""' => 'epoch', | |||||||||||
| 29 | 'eq' => 'equals', | ||||||||||||
| 30 | 'cmp' => 'cmpDate', | ||||||||||||
| 31 | '==' => 'nequals', | ||||||||||||
| 32 | 6 | ▶ | '<=>' => 'ncmpDate'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | |||||||||||||
| 34 | sub new { | ||||||||||||
| 35 | 0 | ▶ | my ($class, $date) = @_; | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 36 | |||||||||||||
| 37 | 0 | my $date = str2time $date; | |||||||||||
| 38 | 0 | ▶ | $date ||= 0; | ||||||||||
|
Condition0%0/2
$date ||= 0
MC/DC0%0/1
$date ||= 0
$date
Truth table0%0/2
A
A= $date
| |||||||||||||
| 39 | |||||||||||||
| 40 | 0 | bless \$date, $class; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | sub newFromEpoch { | ||||||||||||
| 44 | 3 | ▶ | my ($class, $epoch) = @_; | ||||||||||
|
Subroutine
newFromEpoch: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 45 | |||||||||||||
| 46 | 3 | my $self = $epoch; | |||||||||||
| 47 | |||||||||||||
| 48 | 3 | bless \$self, $class; | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | sub epoch { | ||||||||||||
| 52 | 3 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
epoch: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 53 | |||||||||||||
| 54 | 3 | return $$self; | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | sub year { | ||||||||||||
| 58 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
year: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 59 | |||||||||||||
| 60 | 0 | return 1900 + (localtime $$self)[5] | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | sub month { | ||||||||||||
| 64 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
month: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 65 | |||||||||||||
| 66 | 0 | return sprintf '%02u', 1 + (localtime $$self)[4] | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | sub imonth { | ||||||||||||
| 70 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
imonth: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 71 | |||||||||||||
| 72 | 0 | return 1 + (localtime $$self)[4] | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | sub mday { | ||||||||||||
| 76 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
mday: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 77 | |||||||||||||
| 78 | 0 | return sprintf '%02u', (localtime $$self)[3] | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | sub imday { | ||||||||||||
| 82 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
imday: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 83 | |||||||||||||
| 84 | 0 | return (localtime $$self)[3] | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | sub day { | ||||||||||||
| 88 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
day: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 89 | |||||||||||||
| 90 | 0 | return sprintf '%02u', (localtime $$self)[3] | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | sub iday { | ||||||||||||
| 94 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
iday: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 95 | |||||||||||||
| 96 | 0 | return (localtime $$self)[3] | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | sub hour { | ||||||||||||
| 100 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
hour: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 101 | |||||||||||||
| 102 | 0 | return sprintf '%02u', (localtime $$self)[2] | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | sub ihour { | ||||||||||||
| 106 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
ihour: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 107 | |||||||||||||
| 108 | 0 | return (localtime $$self)[2] | |||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | sub hour12 { | ||||||||||||
| 112 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
hour12: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 113 | |||||||||||||
| 114 | 0 | return sprintf '%02u', (localtime $$self)[2] % 12; | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | sub ihour12 { | ||||||||||||
| 118 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
ihour12: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 119 | |||||||||||||
| 120 | 0 | return (localtime $$self)[2] % 12; | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | sub ampm { | ||||||||||||
| 124 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
ampm: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 125 | |||||||||||||
| 126 | 0 | return strftime '%p', localtime $$self; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | sub dst { | ||||||||||||
| 130 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
dst: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 131 | |||||||||||||
| 132 | # TRANSLATORS: This stands for "Daylight Savings Time". | ||||||||||||
| 133 | 0 | ▶ | return (localtime $$self)[8] ? __"DST" : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 134 | } | ||||||||||||
| 135 | |||||||||||||
| 136 | sub wdayname { | ||||||||||||
| 137 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
wdayname: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 138 | |||||||||||||
| 139 | 0 | return strftime '%A', localtime $$self; | |||||||||||
| 140 | } | ||||||||||||
| 141 | |||||||||||||
| 142 | sub awdayname { | ||||||||||||
| 143 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
awdayname: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 144 | |||||||||||||
| 145 | 0 | return strftime '%a', localtime $$self; | |||||||||||
| 146 | } | ||||||||||||
| 147 | |||||||||||||
| 148 | sub monthname { | ||||||||||||
| 149 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
monthname: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 150 | |||||||||||||
| 151 | 0 | return strftime '%B', localtime $$self; | |||||||||||
| 152 | } | ||||||||||||
| 153 | |||||||||||||
| 154 | sub amonthname { | ||||||||||||
| 155 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
amonthname: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 156 | |||||||||||||
| 157 | 0 | return strftime '%b', localtime $$self; | |||||||||||
| 158 | } | ||||||||||||
| 159 | |||||||||||||
| 160 | sub ISOString { | ||||||||||||
| 161 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
ISOString: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 162 | |||||||||||||
| 163 | 0 | my @then = gmtime $$self; | |||||||||||
| 164 | |||||||||||||
| 165 | 0 | return sprintf '%04u-%02u-%02uT%02u:%02u:%02u.000Z', | |||||||||||
| 166 | $then[5] + 1900, $then[4] + 1, $then[3], | ||||||||||||
| 167 | $then[2], $then[1], $then[0] | ||||||||||||
| 168 | } | ||||||||||||
| 169 | |||||||||||||
| 170 | sub cmpDate { | ||||||||||||
| 171 | 0 | ▶ | my ($self, $other, $swap) = @_; | ||||||||||
|
Subroutine
cmpDate: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 172 | |||||||||||||
| 173 | 0 | my $result = $self->ISOString cmp $other; | |||||||||||
| 174 | 0 | ▶ | $result = -$result if $swap; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 175 | |||||||||||||
| 176 | 0 | return $result; | |||||||||||
| 177 | } | ||||||||||||
| 178 | |||||||||||||
| 179 | sub ncmpDate { | ||||||||||||
| 180 | 3 | ▶ | my ($self, $other, $swap) = @_; | ||||||||||
|
Subroutine
ncmpDate: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 181 | |||||||||||||
| 182 | 3 | my $result = $self->epoch <=> $other; | |||||||||||
| 183 | 3 | ▶ | $result = -$result if $swap; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 184 | |||||||||||||
| 185 | 3 | return $result; | |||||||||||
| 186 | } | ||||||||||||
| 187 | |||||||||||||
| 188 | sub equals { | ||||||||||||
| 189 | 0 | ▶ | my ($self, $other) = @_; | ||||||||||
|
Subroutine
equals: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 190 | |||||||||||||
| 191 | 0 | return "$self" eq "$other"; | |||||||||||
| 192 | } | ||||||||||||
| 193 | |||||||||||||
| 194 | sub nequals { | ||||||||||||
| 195 | 0 | ▶ | my ($self, $other) = @_; | ||||||||||
|
Subroutine
nequals: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 196 | |||||||||||||
| 197 | 0 | return $$self == $other; | |||||||||||
| 198 | } | ||||||||||||
| 199 | |||||||||||||
| 200 | 6 | 1; | |||||||||||