| 1 | package SPVM::Time::Seconds; | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | 1 | 1; | |
| 6 | |||
| 7 | =head1 Name | ||
| 8 | |||
| 9 | SPVM::Time::Seconds - Seconds | ||
| 10 | |||
| 11 | =head1 Description | ||
| 12 | |||
| 13 | Time::Seconds class in L<SPVM> has methods to manipulate seconds to calculate dates and times. | ||
| 14 | |||
| 15 | =head1 Usage | ||
| 16 | |||
| 17 | use Time::Piece; | ||
| 18 | use Time::Seconds; | ||
| 19 | |||
| 20 | my $tp = Time::Piece->localtime; | ||
| 21 | $tp = $tp->add(Time::Seconds->ONE_DAY); | ||
| 22 | |||
| 23 | my $tp2 = Time::Piece->localtime; | ||
| 24 | my $tsec = $tp->subtract_tp($tp2); | ||
| 25 | |||
| 26 | say "Difference is: " . $tsec->days; | ||
| 27 | |||
| 28 | =head1 Details | ||
| 29 | |||
| 30 | The class makes the assumption that there are 24 hours in a day, 7 days in a week, 365.24225 days in a year and 12 months in a year. | ||
| 31 | |||
| 32 | =head1 Interfaces | ||
| 33 | |||
| 34 | =over 2 | ||
| 35 | |||
| 36 | =item L<Cloneable|SPVM::Cloneable> | ||
| 37 | |||
| 38 | =back | ||
| 39 | |||
| 40 | =head1 Fields | ||
| 41 | |||
| 42 | =head2 seconds | ||
| 43 | |||
| 44 | C<has seconds : ro long;> | ||
| 45 | |||
| 46 | Seconds. | ||
| 47 | |||
| 48 | =head1 Class Methods | ||
| 49 | |||
| 50 | =head2 new | ||
| 51 | |||
| 52 | C<static method new : L<Time::Seconds|SPVM::Time::Seconds> ($second : long = 0);> | ||
| 53 | |||
| 54 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given seconds $second, and returns it. | ||
| 55 | |||
| 56 | =head2 ONE_MINUTE | ||
| 57 | |||
| 58 | C<static method ONE_MINUTE : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 59 | |||
| 60 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 minute, and returns it. | ||
| 61 | |||
| 62 | =head2 ONE_HOUR | ||
| 63 | |||
| 64 | C<static method ONE_HOUR : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 65 | |||
| 66 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 hour, and returns it. | ||
| 67 | |||
| 68 | =head2 ONE_DAY | ||
| 69 | |||
| 70 | C<static method ONE_DAY : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 71 | |||
| 72 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 day, and returns it. | ||
| 73 | |||
| 74 | =head2 ONE_WEEK | ||
| 75 | |||
| 76 | C<static method ONE_WEEK : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 77 | |||
| 78 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 week, and returns it. | ||
| 79 | |||
| 80 | =head2 ONE_MONTH | ||
| 81 | |||
| 82 | C<static method ONE_MONTH : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 83 | |||
| 84 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 month, and returns it. | ||
| 85 | |||
| 86 | =head2 ONE_YEAR | ||
| 87 | |||
| 88 | C<static method ONE_YEAR : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 89 | |||
| 90 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 year, and returns it. | ||
| 91 | |||
| 92 | =head2 ONE_FINANCIAL_MONTH | ||
| 93 | |||
| 94 | C<static method ONE_FINANCIAL_MONTH : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 95 | |||
| 96 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 financial day, and returns it. | ||
| 97 | |||
| 98 | =head2 LEAP_YEAR | ||
| 99 | |||
| 100 | C<static method LEAP_YEAR : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 101 | |||
| 102 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 year that is a leap year, and returns it. | ||
| 103 | |||
| 104 | =head2 NON_LEAP_YEAR | ||
| 105 | |||
| 106 | C<static method NON_LEAP_YEAR : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 107 | |||
| 108 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object given the seconds correspond to 1 year that is not a leap year, and returns it. | ||
| 109 | |||
| 110 | =head1 Instance Methods | ||
| 111 | |||
| 112 | =head2 add | ||
| 113 | |||
| 114 | C<method add : Time::Seconds ($seconds : long);> | ||
| 115 | |||
| 116 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object with seconds $seconds added to the current seconds, and returns it. | ||
| 117 | |||
| 118 | =head2 subtract | ||
| 119 | |||
| 120 | C<method subtract : Time::Seconds ($seconds : long);> | ||
| 121 | |||
| 122 | Creates a new L<Time::Seconds|SPVM::Time::Seconds> object with seconds $seconds subtracted from the current seconds, and returns it. | ||
| 123 | |||
| 124 | =head2 minutes | ||
| 125 | |||
| 126 | C<method minutes : double ();> | ||
| 127 | |||
| 128 | Calculates the minutes, and returns it. | ||
| 129 | |||
| 130 | =head2 hours | ||
| 131 | |||
| 132 | C<method hours : double ();> | ||
| 133 | |||
| 134 | Calculates the hours, and returns it. | ||
| 135 | |||
| 136 | =head2 days | ||
| 137 | |||
| 138 | C<method days : double ();> | ||
| 139 | |||
| 140 | Calculates the days, and returns it. | ||
| 141 | |||
| 142 | =head2 weeks | ||
| 143 | |||
| 144 | C<method weeks : double ();> | ||
| 145 | |||
| 146 | Calculates the weeks, and returns it. | ||
| 147 | |||
| 148 | =head2 months | ||
| 149 | |||
| 150 | C<method months : double ();> | ||
| 151 | |||
| 152 | Calculates the months, and returns it. | ||
| 153 | |||
| 154 | =head2 financial_months | ||
| 155 | |||
| 156 | C<method financial_months : double ();> | ||
| 157 | |||
| 158 | Calculates the financial months, and returns it. | ||
| 159 | |||
| 160 | =head2 years | ||
| 161 | |||
| 162 | C<method years : double ();> | ||
| 163 | |||
| 164 | Calculates the financial years, and returns it. | ||
| 165 | |||
| 166 | =head2 clone | ||
| 167 | |||
| 168 | C<method clone : L<Time::Seconds|SPVM::Time::Seconds> ();> | ||
| 169 | |||
| 170 | Clones this instance and returns it. | ||
| 171 | |||
| 172 | =head2 pretty | ||
| 173 | |||
| 174 | C<method pretty : string ();> | ||
| 175 | |||
| 176 | Interprets L</"seconds"> as a delta and returns an English expression. | ||
| 177 | |||
| 178 | =head1 Copyright & License | ||
| 179 | |||
| 180 | Copyright (c) 2023 Yuki Kimoto | ||
| 181 | |||
| 182 | MIT License | ||
| 183 |