Pyjo.Date - HTTP date¶
from Pyjo.Date import Date
# Parse
date = Date('Sun, 06 Nov 1994 08:49:37 GMT')
print(date.epoch)
# Or import the module, as in Google Python Style Guide
import Pyjo.Date
import time
# Parse
date = Pyjo.Date.new('Sun, 06 Nov 1994 08:49:37 GMT')
print(date.epoch)
# Build
date = Pyjo.Date.new(time.time() + 60)
print(date)
Pyjo.Date implements HTTP date and time functions, based on RFC 7230,
RFC 7231 and RFC 3339.
See also¶
Pyjoyment, https://mojolicious.org.
Ported from Mojo::Date of Mojolicious 9.49.
Classes¶
- class Pyjo.Date.Pyjo_Date(date: str | float | datetime | None = None)[source]¶
Pyjo.Dateinherits all methods fromPyjo.BaseandPyjo.String.Mixinand implements the following new ones.- epoch: int | float | None¶
epoch = date.epoch date.epoch = 784111777
Epoch seconds, defaults to the current time.
- parse(date: str | float | datetime) Self[source]¶
date = date.parse('Sun Nov 6 08:49:37 1994') date = date.parse(datetime.now(UTC))
Parse date. A
datetime.datetimegives its timestamp, so a naive one is local time, as fordatetime.datetime.timestamp().# Epoch print(Pyjo.Date.new('784111777').epoch) print(Pyjo.Date.new('784111777.21').epoch) # RFC 822/1123 print(Pyjo.Date.new('Sun, 06 Nov 1994 08:49:37 GMT').epoch) # RFC 850/1036 print(Pyjo.Date.new('Sunday, 06-Nov-94 08:49:37 GMT').epoch) # Ansi C asctime() print(Pyjo.Date.new('Sun Nov 6 08:49:37 1994').epoch) # RFC 3339 print(Pyjo.Date.new('1994-11-06T08:49:37Z').epoch) print(Pyjo.Date.new('1994-11-06T08:49:37').epoch) print(Pyjo.Date.new('1994-11-06T08:49:37.21Z').epoch) print(Pyjo.Date.new('1994-11-06T08:49:37+01:00').epoch) print(Pyjo.Date.new('1994-11-06T08:49:37-01:00').epoch)
- to_datetime() datetime[source]¶
dt = date.to_datetime()
Turn date into a
datetime.datetimein UTC, for the standard library.# datetime.datetime(1994, 11, 6, 8, 49, 37, tzinfo=datetime.timezone.utc) Pyjo.Date.new(784111777).to_datetime()