1Mojo::Date(3) User Contributed Perl Documentation Mojo::Date(3)
2
3
4
6 Mojo::Date - HTTP date
7
9 use Mojo::Date;
10
11 # Parse
12 my $date = Mojo::Date->new('Sun, 06 Nov 1994 08:49:37 GMT');
13 say $date->epoch;
14
15 # Build
16 my $date = Mojo::Date->new(time + 60);
17 say "$date";
18
20 Mojo::Date implements HTTP date and time functions, based on RFC 7230
21 <http://tools.ietf.org/html/rfc7230>, RFC 7231
22 <http://tools.ietf.org/html/rfc7231> and RFC 3339
23 <http://tools.ietf.org/html/rfc3339>.
24
26 Mojo::Date implements the following attributes.
27
28 epoch
29 my $epoch = $date->epoch;
30 $date = $date->epoch(784111777);
31
32 Epoch seconds, defaults to the current time.
33
35 Mojo::Date inherits all methods from Mojo::Base and implements the
36 following new ones.
37
38 new
39 my $date = Mojo::Date->new;
40 my $date = Mojo::Date->new('Sun Nov 6 08:49:37 1994');
41
42 Construct a new Mojo::Date object and "parse" date if necessary.
43
44 parse
45 $date = $date->parse('Sun Nov 6 08:49:37 1994');
46
47 Parse date.
48
49 # Epoch
50 say Mojo::Date->new('784111777')->epoch;
51 say Mojo::Date->new('784111777.21')->epoch;
52
53 # RFC 822/1123
54 say Mojo::Date->new('Sun, 06 Nov 1994 08:49:37 GMT')->epoch;
55
56 # RFC 850/1036
57 say Mojo::Date->new('Sunday, 06-Nov-94 08:49:37 GMT')->epoch;
58
59 # Ansi C asctime()
60 say Mojo::Date->new('Sun Nov 6 08:49:37 1994')->epoch;
61
62 # RFC 3339
63 say Mojo::Date->new('1994-11-06T08:49:37Z')->epoch;
64 say Mojo::Date->new('1994-11-06T08:49:37')->epoch;
65 say Mojo::Date->new('1994-11-06T08:49:37.21Z')->epoch;
66 say Mojo::Date->new('1994-11-06T08:49:37+01:00')->epoch;
67 say Mojo::Date->new('1994-11-06T08:49:37-01:00')->epoch;
68
69 to_datetime
70 my $str = $date->to_datetime;
71
72 Render RFC 3339 <http://tools.ietf.org/html/rfc3339> date and time.
73
74 # "1994-11-06T08:49:37Z"
75 Mojo::Date->new(784111777)->to_datetime;
76
77 # "1994-11-06T08:49:37.21Z"
78 Mojo::Date->new(784111777.21)->to_datetime;
79
80 to_string
81 my $str = $date->to_string;
82
83 Render date suitable for HTTP messages.
84
85 # "Sun, 06 Nov 1994 08:49:37 GMT"
86 Mojo::Date->new(784111777)->to_string;
87
89 Mojo::Date overloads the following operators.
90
91 bool
92 my $bool = !!$date;
93
94 Always true.
95
96 stringify
97 my $str = "$date";
98
99 Alias for "to_string".
100
102 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
103
104
105
106perl v5.32.0 2020-07-28 Mojo::Date(3)