Venus::Date - Date Class
Date Class for Perl 5
package main; use Venus::Date; my $date = Venus::Date->new(570672000); # $date->string; # '1988-02-01T00:00:00Z'
This package provides methods for formatting, parsing, and manipulating date and time data.
This package has the following attributes:
day(Int)
This attribute is read-write, accepts (Int) values, and is optional.
(Int)
month(Int)
year(Int)
hour(Int)
minute(Int)
second(Int)
This package inherits behaviors from:
Venus::Kind::Utility
This package integrates behaviors from:
Venus::Role::Buildable
Venus::Role::Explainable
This package provides the following methods:
add(hashref $data) (Venus::Date)
The add method increments the date and time attributes specified.
Since 0.01
0.01
# given: synopsis; $date = $date->add({ days => 1, months => 1, years => 1, }); # $date->string; # 1989-03-03T16:17:54Z # $date->epoch; # 604945074
# given: synopsis; $date = $date->add({ hours => 1, minutes => 1, seconds => 1, }); # $date->string; # 1988-02-01T01:01:01Z # $date->epoch; # 570675661
add_days(number $days) (any)
The add_days method increments the day attribute.
day
# given: synopsis; $date = $date->add_days(1); # $date->string; # 1988-02-02T00:00:00Z # $date->epoch; # 570758400
# given: synopsis; $date = $date->add_days(40); # $date->string; # 1988-03-12T00:00:00Z # $date->epoch; # 574128000
# given: synopsis; $date = $date->add_days(-1); # $date->string; # 1988-01-31T00:00:00Z # $date->epoch; # 570585600
add_hms(maybe[number] $hours, maybe[number] $minutes, maybe[number] $seconds) (Venus::Date)
The add_hms method increments the hour, minute, and second attributes.
hour
minute
second
# given: synopsis; $date = $date->add_hms(1, 0, 0); # $date->string; # 1988-02-01T01:00:00Z # $date->epoch; # 570675600
# given: synopsis; $date = $date->add_hms(undef, 1, 1); # $date->string; # 1988-02-01T00:01:01Z # $date->epoch; # 570672061
# given: synopsis; $date = $date->add_hms(1, 1); # $date->string; # 1988-02-01T01:01:00Z # $date->epoch; # 570675660
add_hours(number $hours) (any)
The add_hours method increments the hour attribute.
# given: synopsis; $date = $date->add_hours(1); # $date->string; # 1988-02-01T01:00:00Z # $date->epoch; # 570675600
# given: synopsis; $date = $date->add_hours(25); # $date->string; # 1988-02-02T01:00:00Z # $date->epoch; # 570762000
# given: synopsis; $date = $date->add_hours(-1); # $date->string; # 1988-01-31T23:00:00Z # $date->epoch; # 570668400
add_mdy(maybe[number] $months, maybe[number] $days, maybe[number] $years) (Venus::Date)
The add_mdy method increments the month, day, and years attributes.
month
years
# given: synopsis; $date = $date->add_mdy(1, 0, 0); # $date->string; # 1988-03-02T10:29:04Z # $date->epoch; # 573301744
# given: synopsis; $date = $date->add_mdy(undef, 1, 1); # $date->string; # 1989-02-01T05:48:50Z # $date->epoch; # 602315330
# given: synopsis; $date = $date->add_mdy(1, 1); # $date->string; # 1988-03-03T10:29:04Z # $date->epoch; # 573388144
add_minutes(number $minutes) (Venus::Date)
The add_minutes method increments the minute attribute.
# given: synopsis; $date = $date->add_minutes(1); # $date->string; # 1988-02-01T00:01:00Z # $date->epoch; # 570672060
# given: synopsis; $date = $date->add_minutes(61); # $date->string; # 1988-02-01T01:01:00Z # $date->epoch; # 570675660
# given: synopsis; $date = $date->add_minutes(-1); # $date->string; # 1988-01-31T23:59:00Z # $date->epoch; # 570671940
add_months(number $months) (Venus::Date)
The add_months method increments the month attribute.
# given: synopsis; $date = $date->add_months(1); # $date->string; # 1988-03-02T10:29:04Z # $date->epoch; # 573301744
# given: synopsis; $date = $date->add_months(13); # $date->string; # 1989-03-02T16:17:52Z # $date->epoch; # 604858672
# given: synopsis; $date = $date->add_months(-1); # $date->string; # 1988-01-01T13:30:56Z # $date->epoch; # 568042256
add_seconds(number $seconds) (Venus::Date)
The add_seconds method increments the second attribute.
# given: synopsis; $date = $date->add_seconds(1); # $date->string; # 1988-02-01T00:00:01Z # $date->epoch; # 570672001
# given: synopsis; $date = $date->add_seconds(61); # $date->string; # 1988-02-01T00:01:01Z # $date->epoch; # 570672061
# given: synopsis; $date = $date->add_seconds(-1); # $date->string; # 1988-01-31T23:59:59Z # $date->epoch; # 570671999
add_years(number $years) (Venus::Date)
The add_years method increments the year attribute.
year
# given: synopsis; $date = $date->add_years(1); # $date->string; # 1989-01-31T05:48:50Z # $date->epoch; # 602228930
# given: synopsis; $date = $date->add_years(50); # $date->string; # 2038-01-31T02:41:40Z # $date->epoch; # 2148518500
# given: synopsis; $date = $date->add_years(-1); # $date->string; # 1987-01-31T18:11:10Z # $date->epoch; # 539115070
epoch() (number)
The epoch method returns the epoch.
# given: synopsis; my $epoch = $date->epoch; # 570672000
explain() (number)
The explain method returns the epoch and is used in stringification operations.
# given: synopsis; my $explain = $date->explain; # 570672000
format(string $format) (string)
The format method returns the formatted date and time string. See strftime for formatting rules.
# given: synopsis; my $format = $date->format('%A, %B %e, %Y'); # Monday, February 1, 1988
# given: synopsis; my $format = $date->format('%b %e %a'); # Feb 1 Mon
hms() (string)
The hms method returns the time formatted as hh:mm:ss.
hh:mm:ss
# given: synopsis; my $hms = $date->hms; # 00:00:00
iso8601() (string)
The iso8601 method returns the date and time formatted as an ISO8601 string.
# given: synopsis; my $iso8601 = $date->iso8601; # 1988-02-01T00:00:00
mdy() (string)
The mdy method returns the date formatted as mm-dd-yyyy.
mm-dd-yyyy
# given: synopsis; my $mdy = $date->mdy; # 02-01-1988
parse(any @data) (Venus::Date)
The parse method resets and returns a date object based on the parsed time provided. See strptime for parsing rules.
# given: synopsis; $date = $date->parse('Monday, February 1, 1988', '%A, %B %e, %Y'); # $date->string; # 1988-02-01T00:00:00Z # $date->epoch; # 570672000
reset(number $time) (Venus::Date)
The reset method resets all attributes to correspond with the epoch provided.
# given: synopsis; $date = $date->reset(631152000); # $date->string; # 1990-01-01T00:00:00Z # $date->epoch; # 631152000
restart(string $interval) (Venus::Date)
The restart method truncates the date and time to the specified unit of time, e.g. year, quarter, month, day, hour, minute, second.
quarter
# given: synopsis; $date = $date->restart('year'); # $date->string; # 1988-01-01T00:00:00Z # $date->epoch; # 567993600
# given: synopsis; $date = $date->restart('quarter'); # $date->string; # 1988-01-01T00:00:00Z # $date->epoch; # 567993600
# given: synopsis; $date = $date->restart('month'); # $date->string; # 1988-02-01T00:00:00Z # $date->epoch; # 570672000
restart_day() (Venus::Date)
The restart_day method truncates the date and time to the day.
Since 1.02
1.02
# given: synopsis; $date = $date->restart_day; # $date->string; # 1988-02-01T00:00:00Z # $date->epoch; # 570672000
restart_hour() (Venus::Date)
The restart_hour method truncates the date and time to the hour.
# given: synopsis; $date = $date->restart_hour; # $date->string; # 1988-02-01T00:00:00Z # $date->epoch; # 570672000
restart_minute() (Venus::Date)
The restart_minute method truncates the date and time to the minute.
# given: synopsis; $date = $date->restart_minute; # $date->string; # 1988-02-01T00:00:00Z # $date->epoch; # 570672000
restart_month() (Venus::Date)
The restart_month method truncates the date and time to the month.
# given: synopsis; $date = $date->restart_month; # $date->string; # 1988-02-01T00:00:00Z # $date->epoch; # 570672000
restart_quarter() (Venus::Date)
The restart_quarter method truncates the date and time to the quarter.
# given: synopsis; $date = $date->restart_quarter; # $date->string; # 1988-01-01T00:00:00Z # $date->epoch; # 567993600
restart_second() (Venus::Date)
The restart_second method truncates the date and time to the second.
# given: synopsis; $date = $date->restart_second; # $date->string; # 1988-02-01T00:00:00Z # $date->epoch; # 570672000
restart_year() (Venus::Date)
The restart_year method truncates the date and time to the year.
# given: synopsis; $date = $date->restart_year; # $date->string; # 1988-01-01T00:00:00Z # $date->epoch; # 567993600
rfc1123() (string)
The rfc1123 method returns the date and time formatted as an RFC1123 string.
# given: synopsis; my $rfc1123 = $date->rfc1123; # Mon, 01 Feb 1988 00:00:00 GMT
rfc3339() (string)
The rfc3339 method returns the date and time formatted as an RFC3339 string.
# given: synopsis; my $rfc3339 = $date->rfc3339; # 1988-02-01T00:00:00Z
rfc7231() (string)
The rfc7231 method returns the date and time formatted as an RFC7231 string.
# given: synopsis; my $rfc7231 = $date->rfc7231; # Mon, 01 Feb 1988 00:00:00 UTC
rfc822() (string)
The rfc822 method returns the date and time formatted as an RFC822 string.
# given: synopsis; my $rfc822 = $date->rfc822; # Mon, 01 Feb 1988 00:00:00 +0000
set(hashref $data) (Venus::Date)
The set method sets the date and time attributes specified.
# given: synopsis; $date = $date->set({ day => 1, month => 1, year => 2000, }); # $date->string; # 2000-01-01T00:00:00Z # $date->epoch; # 946684800
# given: synopsis; $date = $date->set({ day => 1, month => 12, }); # $date->string; # 1988-12-01T00:00:00Z # $date->epoch; # 596937600
# given: synopsis; $date = $date->set({ day => 1, month => 12, year => 1979, }); # $date->string; # 1979-12-01T00:00:00Z # $date->epoch; # 312854400
set_hms(maybe[number] $hours, maybe[number] $minutes, maybe[number] $seconds) (Venus::Date)
The set_hms method sets the hour, minute, and second attributes.
# given: synopsis; $date = $date->set_hms(1, 0, 0); # $date->string; # 1988-02-01T01:00:00Z # $date->epoch; # 570675600
# given: synopsis; $date = $date->set_hms(undef, 30, 30); # $date->string; # 1988-02-01T00:30:30Z # $date->epoch; # 570673830
# given: synopsis; $date = $date->set_hms(0, 59, 59); # $date->string; # 1988-02-01T00:59:59Z # $date->epoch; # 570675599
set_mdy(maybe[number] $months, maybe[number] $days, maybe[number] $years) (Venus::Date)
The set_mdy method sets the month, day, and year attributes.
# given: synopsis; $date = $date->set_mdy(4, 30, 1990); # $date->string; # 1990-04-30T00:00:00Z # $date->epoch; # 641433600
# given: synopsis; $date = $date->set_mdy(4, 30, undef); # $date->string; # 1988-04-30T00:00:00Z # $date->epoch; # 578361600
# given: synopsis; $date = $date->set_mdy(undef, 15, undef); # $date->string; # 1988-02-15T00:00:00Z # $date->epoch; # 571881600
string() (string)
The string method returns a date and time string, and is an alias for "rfc3339".
# given: synopsis; my $string = $date->string; # 1988-02-01T00:00:00Z
sub(hashref $data) (Venus::Date)
The sub method method decrements the date and time attributes specified.
# given: synopsis; $date = $date->sub({ days => 1, months => 1, years => 1, }); # $date->string; # 1986-12-31T07:42:06Z # $date->epoch; # 536398926
# given: synopsis; $date = $date->sub({ hours => 1, minutes => 1, seconds => 1, }); # $date->string; # 1988-01-31T22:58:59Z # $date->epoch; # 570668339
sub_days(number $days) (Venus::Date)
The sub_days method decrements the day attribute.
# given: synopsis; $date = $date->sub_days(1); # $date->string; # 1988-01-31T00:00:00Z # $date->epoch; # 570585600
# given: synopsis; $date = $date->sub_days(32); # $date->string; # 1987-12-31T00:00:00Z # $date->epoch; # 567907200
# given: synopsis; $date = $date->sub_days(-1); # $date->string; # 1988-02-02T00:00:00Z # $date->epoch; # 570758400
sub_hms(maybe[number] $hours, maybe[number] $minutes, maybe[number] $seconds) (Venus::Date)
The sub_hms method decrements the hour, minute, and second attributes.
# given: synopsis; $date = $date->sub_hms(1, 0, 0); # $date->string; # 1988-01-31T23:00:00Z # $date->epoch; # 570668400
# given: synopsis; $date = $date->sub_hms(undef, 1, 1); # $date->string; # 1988-01-31T23:58:59Z # $date->epoch; # 570671939
# given: synopsis; $date = $date->sub_hms(1, 1); # $date->string; # 1988-01-31T22:59:00Z # $date->epoch; # 570668340
sub_hours(number $hours) (any)
The sub_hours method decrements the hour attribute.
# given: synopsis; $date = $date->sub_hours(1); # $date->string; # 1988-01-31T23:00:00Z # $date->epoch; # 570668400
# given: synopsis; $date = $date->sub_hours(25); # $date->string; # 1988-01-30T23:00:00Z # $date->epoch; # 570582000
# given: synopsis; $date = $date->sub_hours(-1); # $date->string; # 1988-02-01T01:00:00Z # $date->epoch; # 570675600
sub_mdy(maybe[number] $months, maybe[number] $days, maybe[number] $years) (Venus::Date)
The sub_mdy method decrements the month, day, and year attributes.
# given: synopsis; $date = $date->sub_mdy(1, 1, 1); # $date->string; # 1986-12-31T07:42:06Z # $date->epoch; # 536398926
# given: synopsis; $date = $date->sub_mdy(1, 1, undef); # $date->string; # 1987-12-31T13:30:56Z # $date->epoch; # 567955856
# given: synopsis; $date = $date->sub_mdy(1, 1); # $date->string; # 1987-12-31T13:30:56Z # $date->epoch; # 567955856
sub_minutes(number $minutes) (Venus::Date)
The sub_minutes method decrements the minute attribute.
# given: synopsis; $date = $date->sub_minutes(1); # $date->string; # 1988-01-31T23:59:00Z # $date->epoch; # 570671940
# given: synopsis; $date = $date->sub_minutes(61); # $date->string; # 1988-01-31T22:59:00Z # $date->epoch; # 570668340
# given: synopsis; $date = $date->sub_minutes(-1); # $date->string; # 1988-02-01T00:01:00Z # $date->epoch; # 570672060
sub_months(number $months) (Venus::Date)
The sub_months method decrements the month attribute.
# given: synopsis; $date = $date->sub_months(1); # $date->string; # 1988-01-01T13:30:56Z # $date->epoch; # 568042256
# given: synopsis; $date = $date->sub_months(13); # $date->string; # 1987-01-01T07:42:08Z # $date->epoch; # 536485328
# given: synopsis; $date = $date->sub_months(-1); # $date->string; # 1988-03-02T10:29:04Z # $date->epoch; # 573301744
sub_seconds(number $seconds) (Venus::Date)
The sub_seconds method decrements the second attribute.
# given: synopsis; $date = $date->sub_seconds(1); # $date->string; # 1988-01-31T23:59:59Z # $date->epoch; # 570671999
# given: synopsis; $date = $date->sub_seconds(61); # $date->string; # 1988-01-31T23:58:59Z # $date->epoch; # 570671939
# given: synopsis; $date = $date->sub_seconds(-1); # $date->string; # 1988-02-01T00:00:01Z # $date->epoch; # 570672001
sub_years(number $years) (Venus::Date)
The sub_years method decrements the years attribute.
# given: synopsis; $date = $date->sub_years(1); # $date->string; # 1987-01-31T18:11:10Z # $date->epoch; # 539115070
# given: synopsis; $date = $date->sub_years(25); # $date->string; # 1963-01-31T22:39:10Z # $date->epoch; # -218251250
# given: synopsis; $date = $date->sub_years(-1); # $date->string; # 1989-01-31T05:48:50Z # $date->epoch; # 602228930
This package overloads the following operators:
(!=)
This package overloads the != operator.
!=
example 1
# given: synopsis; my $result = $date != 570672001; # 1
("")
This package overloads the "" operator.
""
# given: synopsis; my $result = "$date"; # "570672000"
(+)
This package overloads the + operator.
+
# given: synopsis; my $result = $date + 0; # 570672000
(-)
This package overloads the - operator.
-
# given: synopsis; my $result = $date - 0; # 570672000
(0+)
This package overloads the 0+ operator.
0+
# given: synopsis; my $result = 0 + $date; # 570672000
(==)
This package overloads the == operator.
==
# given: synopsis; my $result = $date == 570672000; # 1
(>)
This package overloads the > operator.
>
# given: synopsis; my $result = $date > 570671999; # 1
(>=)
This package overloads the >= operator.
>=
# given: synopsis; my $result = $date >= 570672000; # 1
(<)
This package overloads the < operator.
<
# given: synopsis; my $result = $date < 570672001; # 1
(<=)
This package overloads the <= operator.
<=
# given: synopsis; my $result = $date <= 570672000; # 1
(eq)
This package overloads the eq operator.
eq
# given: synopsis; my $result = $date eq '570672000'; # 1
(ne)
This package overloads the ne operator.
ne
# given: synopsis; my $result = $date ne '560672000'; # 1
(~~)
This package overloads the ~~ operator.
~~
# given: synopsis; my $result = $date ~~ '570672000'; # 1
Awncorp, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2022, Awncorp, awncorp@cpan.org.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.