.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::Date 3pm" .TH Mojo::Date 3pm 2024-05-15 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Mojo::Date \- HTTP date .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Date; \& \& # Parse \& my $date = Mojo::Date\->new(\*(AqSun, 06 Nov 1994 08:49:37 GMT\*(Aq); \& say $date\->epoch; \& \& # Build \& my $date = Mojo::Date\->new(time + 60); \& say "$date"; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Mojo::Date implements HTTP date and time functions, based on RFC 7230 , RFC 7231 and RFC 3339 . .SH ATTRIBUTES .IX Header "ATTRIBUTES" Mojo::Date implements the following attributes. .SS epoch .IX Subsection "epoch" .Vb 2 \& my $epoch = $date\->epoch; \& $date = $date\->epoch(784111777); .Ve .PP Epoch seconds, defaults to the current time. .SH METHODS .IX Header "METHODS" Mojo::Date inherits all methods from Mojo::Base and implements the following new ones. .SS new .IX Subsection "new" .Vb 2 \& my $date = Mojo::Date\->new; \& my $date = Mojo::Date\->new(\*(AqSun Nov 6 08:49:37 1994\*(Aq); .Ve .PP Construct a new Mojo::Date object and "parse" date if necessary. .SS parse .IX Subsection "parse" .Vb 1 \& $date = $date\->parse(\*(AqSun Nov 6 08:49:37 1994\*(Aq); .Ve .PP Parse date. .PP .Vb 3 \& # Epoch \& say Mojo::Date\->new(\*(Aq784111777\*(Aq)\->epoch; \& say Mojo::Date\->new(\*(Aq784111777.21\*(Aq)\->epoch; \& \& # RFC 822/1123 \& say Mojo::Date\->new(\*(AqSun, 06 Nov 1994 08:49:37 GMT\*(Aq)\->epoch; \& \& # RFC 850/1036 \& say Mojo::Date\->new(\*(AqSunday, 06\-Nov\-94 08:49:37 GMT\*(Aq)\->epoch; \& \& # Ansi C asctime() \& say Mojo::Date\->new(\*(AqSun Nov 6 08:49:37 1994\*(Aq)\->epoch; \& \& # RFC 3339 \& say Mojo::Date\->new(\*(Aq1994\-11\-06T08:49:37Z\*(Aq)\->epoch; \& say Mojo::Date\->new(\*(Aq1994\-11\-06T08:49:37\*(Aq)\->epoch; \& say Mojo::Date\->new(\*(Aq1994\-11\-06T08:49:37.21Z\*(Aq)\->epoch; \& say Mojo::Date\->new(\*(Aq1994\-11\-06T08:49:37+01:00\*(Aq)\->epoch; \& say Mojo::Date\->new(\*(Aq1994\-11\-06T08:49:37\-01:00\*(Aq)\->epoch; .Ve .SS to_datetime .IX Subsection "to_datetime" .Vb 1 \& my $str = $date\->to_datetime; .Ve .PP Render RFC 3339 date and time. .PP .Vb 2 \& # "1994\-11\-06T08:49:37Z" \& Mojo::Date\->new(784111777)\->to_datetime; \& \& # "1994\-11\-06T08:49:37.21Z" \& Mojo::Date\->new(784111777.21)\->to_datetime; .Ve .SS to_string .IX Subsection "to_string" .Vb 1 \& my $str = $date\->to_string; .Ve .PP Render date suitable for HTTP messages. .PP .Vb 2 \& # "Sun, 06 Nov 1994 08:49:37 GMT" \& Mojo::Date\->new(784111777)\->to_string; .Ve .SH OPERATORS .IX Header "OPERATORS" Mojo::Date overloads the following operators. .SS bool .IX Subsection "bool" .Vb 1 \& my $bool = !!$date; .Ve .PP Always true. .SS stringify .IX Subsection "stringify" .Vb 1 \& my $str = "$date"; .Ve .PP Alias for "to_string". .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .