| 1 | package Mojo::Calendar; | ||||||||||||
| 2 | 3 | ▶ | use Mojo::Base 'DateTime'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | 3 | our $VERSION = '0.0.5'; | |||||||||||
| 5 | |||||||||||||
| 6 | 3 | ▶ | use DateTime::Format::Flexible; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 21 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=7 SCAR=20.1
Pod
documented
| |||||||||||||
| 9 | 21 | my $class = shift; | |||||||||||
| 10 | 21 | my $args = @_; | |||||||||||
| 11 | |||||||||||||
| 12 | 21 | ▶ | if (@_ > 1) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 13 | 21 | $args = { @_ }; | |||||||||||
| 14 | } else { | ||||||||||||
| 15 | 0 | ▶ | if (ref $_[0] eq 'HASH') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 16 | 0 | $args = $_[0]; | |||||||||||
| 17 | } else { | ||||||||||||
| 18 | 0 | $args = { from => $_[0] }; | |||||||||||
| 19 | } | ||||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | 21 | my $datetime; | |||||||||||
| 23 | |||||||||||||
| 24 | 21 | ▶ | $args->{ locale } ||= 'en_gb'; | ||||||||||
|
Condition100%2/2
$args->{"locale"} ||= "en_gb"
MC/DC100%1/1
$args->{"locale"} ||= "en_gb"
$args->{"locale"}
Truth table100%2/2
A
A= $args->{"locale"}
| |||||||||||||
| 25 | 21 | ▶ | $args->{ time_zone } ||= 'Europe/London'; | ||||||||||
|
Condition100%2/2
$args->{"time_zone"} ||= "Europe/London"
MC/DC100%1/1
$args->{"time_zone"} ||= "Europe/London"
$args->{"time_zone"}
Truth table100%2/2
A
A= $args->{"time_zone"}
| |||||||||||||
| 26 | |||||||||||||
| 27 | 21 | ▶ | if (my $from = delete($args->{ from })) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 3 | $datetime = DateTime::Format::Flexible->parse_datetime($from); | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 21 | ▶ | if (!$datetime) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 18 | $datetime = $class->SUPER::new(%$args); | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | my $self = $class->SUPER::new( | ||||||||||||
| 36 | year => $datetime->year, | ||||||||||||
| 37 | month => $datetime->month, | ||||||||||||
| 38 | day => $datetime->day, | ||||||||||||
| 39 | hour => $datetime->hour, | ||||||||||||
| 40 | minute => $datetime->minute, | ||||||||||||
| 41 | second => $datetime->second, | ||||||||||||
| 42 | nanosecond => $datetime->nanosecond, | ||||||||||||
| 43 | locale => $args->{ locale }, | ||||||||||||
| 44 | time_zone => $args->{ time_zone }, | ||||||||||||
| 45 | 21 | ); | |||||||||||
| 46 | |||||||||||||
| 47 | 21 | return $self; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 6 | ▶ | sub days_ago { | ||||||||||
|
Subroutine
days_ago: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 51 | return shift | ||||||||||||
| 52 | ->clone | ||||||||||||
| 53 | 6 | ->subtract(days => shift); | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 3 | ▶ | sub days_from_now { | ||||||||||
|
Subroutine
days_from_now: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 57 | return shift | ||||||||||||
| 58 | ->clone | ||||||||||||
| 59 | 3 | ->add(days => shift); | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 3 | ▶ | sub first_day_of_next_month { | ||||||||||
|
Subroutine
first_day_of_next_month: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 63 | return shift | ||||||||||||
| 64 | ->clone | ||||||||||||
| 65 | 3 | ->set_day(1) | |||||||||||
| 66 | ->months_from_now(1); | ||||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 0 | ▶ | sub first_day_of_prev_month { | ||||||||||
|
Subroutine
first_day_of_prev_month: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 70 | return shift | ||||||||||||
| 71 | 0 | ->set_day(1) | |||||||||||
| 72 | ->months_ago(1); | ||||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 3 | ▶ | sub months_ago { | ||||||||||
|
Subroutine
months_ago: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 76 | return shift | ||||||||||||
| 77 | ->clone | ||||||||||||
| 78 | 3 | ->subtract(months => shift); | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 3 | ▶ | sub months_from_now { | ||||||||||
|
Subroutine
months_from_now: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 82 | return shift | ||||||||||||
| 83 | ->clone | ||||||||||||
| 84 | 3 | ->add(months => shift); | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | 3 | ▶ | sub today { | ||||||||||
|
Subroutine
today: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 88 | 3 | return shift->clone; | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | 3 | ▶ | sub tomorrow { | ||||||||||
|
Subroutine
tomorrow: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 92 | 3 | return shift->days_from_now(1); | |||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | 3 | ▶ | sub yesterday { | ||||||||||
|
Subroutine
yesterday: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 96 | 3 | return shift->days_ago(1); | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | 3 | 1; | |||||||||||
| 100 | |||||||||||||
| 101 | =encoding utf8 | ||||||||||||
| 102 | |||||||||||||
| 103 | =head1 NAME | ||||||||||||
| 104 | |||||||||||||
| 105 | Mojo::Calendar - Extended DateTime manipulator | ||||||||||||
| 106 | |||||||||||||
| 107 | =head1 SYNOPSIS | ||||||||||||
| 108 | |||||||||||||
| 109 | use Mojo::Calendar; | ||||||||||||
| 110 | |||||||||||||
| 111 | # Calendar with default date being now | ||||||||||||
| 112 | my $calendar = Mojo::Calendar->new; | ||||||||||||
| 113 | |||||||||||||
| 114 | say $calendar->ymd; | ||||||||||||
| 115 | say $calendar->his; | ||||||||||||
| 116 | |||||||||||||
| 117 | say $calendar->tomorrow->ymd; | ||||||||||||
| 118 | |||||||||||||
| 119 | # Calendar with default date being now | ||||||||||||
| 120 | my $calendar = Mojo::Calendar->new; | ||||||||||||
| 121 | |||||||||||||
| 122 | say $calendar->ymd; | ||||||||||||
| 123 | say $calendar->his; | ||||||||||||
| 124 | |||||||||||||
| 125 | # Calendar with default date being 2019-03-28 15:29:00 | ||||||||||||
| 126 | my $calendar = Mojo::Calendar->new('2019-03-28 15:29:00'); | ||||||||||||
| 127 | |||||||||||||
| 128 | say $calendar->ymd; | ||||||||||||
| 129 | say $calendar->his; | ||||||||||||
| 130 | |||||||||||||
| 131 | =head1 DESCRIPTION | ||||||||||||
| 132 | |||||||||||||
| 133 | L<Mojo::Calendar> is a DateTime manipulator which includes humman readable methods. | ||||||||||||
| 134 | |||||||||||||
| 135 | =head1 ATTRIBUTES | ||||||||||||
| 136 | |||||||||||||
| 137 | L<Mojo::Calendar> inherits all attributes from L<DateTime>. | ||||||||||||
| 138 | |||||||||||||
| 139 | =head1 METHODS | ||||||||||||
| 140 | |||||||||||||
| 141 | L<Mojo::Calendar> inherits all methods from L<DateTime> and implements | ||||||||||||
| 142 | the following new ones. | ||||||||||||
| 143 | |||||||||||||
| 144 | =head2 new | ||||||||||||
| 145 | |||||||||||||
| 146 | my $datetime = Mojo::Calendar->new; | ||||||||||||
| 147 | |||||||||||||
| 148 | Calendar object. | ||||||||||||
| 149 | |||||||||||||
| 150 | =head2 days_ago | ||||||||||||
| 151 | |||||||||||||
| 152 | my $datetime = $calendar->days_ago(2); | ||||||||||||
| 153 | |||||||||||||
| 154 | 2 days since initial datetime. | ||||||||||||
| 155 | |||||||||||||
| 156 | =head2 days_from_now | ||||||||||||
| 157 | |||||||||||||
| 158 | my $datetime = $calendar->days_from_now(2); | ||||||||||||
| 159 | |||||||||||||
| 160 | 2 days from initial datetime. | ||||||||||||
| 161 | |||||||||||||
| 162 | =head2 first_day_of_next_month | ||||||||||||
| 163 | |||||||||||||
| 164 | my $datetime = $calendar->first_day_of_next_month; | ||||||||||||
| 165 | |||||||||||||
| 166 | First day of next month from initial datetime. | ||||||||||||
| 167 | |||||||||||||
| 168 | =head2 first_day_of_prev_month | ||||||||||||
| 169 | |||||||||||||
| 170 | my $datetime = $calendar->first_day_of_prev_month; | ||||||||||||
| 171 | |||||||||||||
| 172 | First day of previous month from initial datetime. | ||||||||||||
| 173 | |||||||||||||
| 174 | =head2 months_ago | ||||||||||||
| 175 | |||||||||||||
| 176 | my $datetime = $calendar->months_ago(3); | ||||||||||||
| 177 | |||||||||||||
| 178 | 3 months since initial datetime. | ||||||||||||
| 179 | |||||||||||||
| 180 | =head2 months_from_now | ||||||||||||
| 181 | |||||||||||||
| 182 | my $datetime = $calendar->months_from_now(3); | ||||||||||||
| 183 | |||||||||||||
| 184 | 3 months from initial datetime. | ||||||||||||
| 185 | |||||||||||||
| 186 | =head2 today | ||||||||||||
| 187 | |||||||||||||
| 188 | my $datetime = $calendar->today; | ||||||||||||
| 189 | |||||||||||||
| 190 | today based on initial datetime. | ||||||||||||
| 191 | |||||||||||||
| 192 | =head2 tomorrow | ||||||||||||
| 193 | |||||||||||||
| 194 | my $datetime = $calendar->tomorrow; | ||||||||||||
| 195 | |||||||||||||
| 196 | tomorrow based on initial datetime. | ||||||||||||
| 197 | |||||||||||||
| 198 | =head2 yesterday | ||||||||||||
| 199 | |||||||||||||
| 200 | my $datetime = $calendar->yesterday; | ||||||||||||
| 201 | |||||||||||||
| 202 | yesterday based on initial datetime. | ||||||||||||
| 203 | |||||||||||||
| 204 | =head1 SEE ALSO | ||||||||||||
| 205 | |||||||||||||
| 206 | L<DateTime>, L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||||||||||
| 207 | |||||||||||||
| 208 | =cut | ||||||||||||