Interface¶
Delorean¶
-
class
delorean.
Delorean
(datetime=None, timezone=None)¶ The class Delorean <Delorean> object. This method accepts naive datetime objects, with a string timezone.
-
date
¶ Returns the actual date object associated with the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1, 12, 15), timezone='US/Pacific') >>> d.date datetime.date(2015, 1, 1)
-
datetime
¶ Returns the actual datetime object associated with the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1, 12, 15), timezone='UTC') >>> d.datetime datetime.datetime(2015, 1, 1, 12, 15, tzinfo=<UTC>)
-
end_of_day
¶ Returns the end of the day for the datetime assocaited with the Delorean object, modifying the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1, 12), timezone='UTC') >>> d.end_of_day datetime.datetime(2015, 1, 1, 23, 59, 59, 999999, tzinfo=<UTC>)
-
epoch
¶ Returns the total seconds since epoch associated with the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1), timezone='US/Pacific') >>> d.epoch 1420099200.0
-
format_datetime
(format='medium', locale='en_US')¶ Return a date string formatted to the given pattern.
>>> d = Delorean(datetime(2015, 1, 1, 12, 30), timezone='US/Pacific') >>> d.format_datetime(locale='en_US') u'Jan 1, 2015, 12:30:00 PM' >>> d.format_datetime(format='long', locale='de_DE') u'1. Januar 2015 12:30:00 -0800'
Parameters: - format – one of “full”, “long”, “medium”, “short”, or a custom datetime pattern
- locale – a locale identifier
-
humanize
()¶ Humanize relative to now:
>>> past = Delorean.utcnow() - timedelta(hours=1) >>> past.humanize() 'an hour ago'
-
midnight
¶ Returns midnight for datetime associated with the Delorean object modifying the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1, 12), timezone='UTC') >>> d.midnight datetime.datetime(2015, 1, 1, 0, 0, tzinfo=<UTC>)
-
naive
¶ Returns a naive datetime object associated with the Delorean object, this method simply converts the localize datetime to UTC and removes the tzinfo that is associated with it modifying the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1), timezone='US/Pacific') >>> d.naive datetime.datetime(2015, 1, 1, 8, 0)
-
replace
(**kwargs)¶ Returns a new Delorean object after applying replace on the existing datetime object.
>>> d = Delorean(datetime(2015, 1, 1, 12, 15), timezone='UTC') >>> d.replace(hour=8) Delorean(datetime=datetime.datetime(2015, 1, 1, 8, 15), timezone='UTC')
-
shift
(timezone)¶ Shifts the timezone from the current timezone to the specified timezone associated with the Delorean object, modifying the Delorean object and returning the modified object.
>>> d = Delorean(datetime(2015, 1, 1), timezone='US/Pacific') >>> d.shift('UTC') Delorean(datetime=datetime.datetime(2015, 1, 1, 8, 0), timezone='UTC')
-
start_of_day
¶ Returns the start of the day for datetime assoicated with the Delorean object, modifying the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1, 12), timezone='UTC') >>> d.start_of_day datetime.datetime(2015, 1, 1, 0, 0, tzinfo=<UTC>)
-
timezone
¶ Returns a valid tzinfo object associated with the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1), timezone='UTC') >>> d.timezone <UTC>
-
truncate
(s)¶ Truncate the delorian object to the nearest s (second, minute, hour, day, month, year)
This is a destructive method, modifies the internal datetime object associated with the Delorean object.
>>> d = Delorean(datetime(2015, 1, 1, 12, 10), timezone='US/Pacific') >>> d.truncate('hour') Delorean(datetime=datetime.datetime(2015, 1, 1, 12, 0), timezone='US/Pacific')
-
-
exception
delorean.
DeloreanInvalidDatetime
(msg)¶ Exception that is raised when an improper datetime object is passed in.
-
exception
delorean.
DeloreanInvalidTimezone
(msg)¶ Exception that is raised when an invalid timezone is passed in.
-
delorean.
datetime_timezone
(tz)¶ This method given a timezone returns a localized datetime object.
-
delorean.
localize
(dt, tz)¶ Given a naive datetime object this method will return a localized datetime object
-
delorean.
move_datetime_month
(dt, direction, num_shifts)¶ Move datetime 1 month in the chosen direction. unit is a no-op, to keep the API the same as the day case
-
delorean.
move_datetime_week
(dt, direction, num_shifts)¶ Move datetime 1 week in the chosen direction. unit is a no-op, to keep the API the same as the day case
-
delorean.
move_datetime_year
(dt, direction, num_shifts)¶ Move datetime 1 year in the chosen direction. unit is a no-op, to keep the API the same as the day case
-
delorean.
normalize
(dt, tz)¶ Given a object with a timezone return a datetime object normalized to the proper timezone.
This means take the give localized datetime and returns the datetime normalized to match the specificed timezone.
-
delorean.
now
(timezone=None)¶ Return a Delorean object for the current local date and time, setting the timezone to the local timezone of the caller by default.
Parameters: timezone (Optional[datetime.tzinfo]) – A custom timezone to use when computing the time. Return type: delorean.dates.Delorean
-
delorean.
parse
(datetime_str, timezone=None, isofirst=True, dayfirst=True, yearfirst=True)¶ Parses a datetime string and returns a Delorean object.
Parameters: - datetime_str – The string to be interpreted into a Delorean object.
- timezone – Pass this parameter and the returned Delorean object will be normalized to this timezone. Any offsets passed as part of datetime_str will be ignored.
- isofirst – try to parse string as date in ISO format before everything else.
- dayfirst – Whether to interpret the first value in an ambiguous 3-integer date (ex. 01/05/09) as the day (True) or month (False). If yearfirst is set to True, this distinguishes between YDM and YMD.
- yearfirst – Whether to interpret the first value in an ambiguous 3-integer date (ex. 01/05/09) as the year. If True, the first number is taken to be the year, otherwise the last number is taken to be the year.
>>> parse('2015-01-01 00:01:02') Delorean(datetime=datetime.datetime(2015, 1, 1, 0, 1, 2), timezone='UTC')
If a fixed offset is provided in the datetime_str, it will be parsed and the returned Delorean object will store a pytz.FixedOffest as it’s timezone.
>>> parse('2015-01-01 00:01:02 -0800') Delorean(datetime=datetime.datetime(2015, 1, 1, 0, 1, 2), timezone=pytz.FixedOffset(-480))
If the timezone argument is supplied, the returned Delorean object will be in the timezone supplied. Any offsets in the datetime_str will be ignored.
>>> parse('2015-01-01 00:01:02 -0500', timezone='US/Pacific') Delorean(datetime=datetime.datetime(2015, 1, 1, 0, 1, 2), timezone='US/Pacific')
If an unambiguous timezone is detected in the datetime string, a Delorean object with that datetime and timezone will be returned.
>>> parse('2015-01-01 00:01:02 PST') Delorean(datetime=datetime.datetime(2015, 1, 1, 0, 1, 2), timezone='America/Los_Angeles')
However if the provided timezone is ambiguous, parse will ignore the timezone and return a Delorean object in UTC time.
>>> parse('2015-01-01 00:01:02 EST') Delorean(datetime=datetime.datetime(2015, 1, 1, 0, 1, 2), timezone='UTC')
-
delorean.
range_daily
(start=None, stop=None, timezone='UTC', count=None)¶ This an alternative way to generating sets of Delorean objects with DAILY stops
-
delorean.
range_hourly
(start=None, stop=None, timezone='UTC', count=None)¶ This an alternative way to generating sets of Delorean objects with HOURLY stops
-
delorean.
range_monthly
(start=None, stop=None, timezone='UTC', count=None)¶ This an alternative way to generating sets of Delorean objects with MONTHLY stops
-
delorean.
range_yearly
(start=None, stop=None, timezone='UTC', count=None)¶ This an alternative way to generating sets of Delorean objects with YEARLY stops
-
delorean.
stops
(freq, interval=1, count=None, wkst=None, bysetpos=None, bymonth=None, bymonthday=None, byyearday=None, byeaster=None, byweekno=None, byweekday=None, byhour=None, byminute=None, bysecond=None, timezone='UTC', start=None, stop=None)¶ This will create a list of delorean objects the apply to setting possed in.
-
delorean.
utcnow
()¶ Return a Delorean object for the current UTC date and time, setting the timezone to UTC.