Date, Time, Start and End Time of Query, Timezones#
otp.datetime class#
Classes datetime
and date
are used for representing times in otp. They support several initializations:
# initialization by datetime.datetime class from standard library
>>> otp.datetime(datetime(2019, 1, 1, 1))
2019-01-01 01:00:00
# initialization by pandas Timestamp class
>>> otp.datetime(pd.Timestamp(2019, 1, 1, 1))
2019-01-01 01:00:00
# initialization by int timestamp
>>> otp.datetime(1234567890)
1970-01-01 00:00:01.234567890
# initialization by string
>>> otp.datetime("2019/01/01 1:02")
2019-01-01 01:02:00
# otp.dt is the alias for otp.datetime
>>> otp.dt(2019, 1, 1)
2019-01-01 00:00:00-05:00
Timezones#
Timezone of date can be specified by tzinfo
or timezone
arguments of
otp.datetime
# timezone can be change by ``replace`` method, unfortunately it
# support only ``tzinfo`` parameter and doesn't support ``tz`` argument.
>>> otp.datetime(2019, 1, 1, 17, 30, tz="America/New_York").replace(tzinfo=pytz.timezone("GMT"))
2019-01-01 17:30:00+00:00
Start and End Arguments of the Query#
Every query should have start and end time. By default every query in otp runs
from otp.config.default_start_time
to otp.config.default_end_time
. Custom query
time range can be specified by start
and end
arguments.
You can specify them during Ticks
initialization
or as parameter of query run, e.g. in to_df()
method.
Time X
0 2019-01-01 00:00:00.000 1
1 2019-01-01 00:00:00.001 2
2 2019-01-01 00:00:00.002 3
Time X
0 2019-01-01 00:00:00.000 1
1 2019-01-01 00:00:00.001 2
2 2019-01-01 00:00:00.002 3
otp.datetime
has predefined start and end field, they initialized at the
beginning and at the ending of the day.
Time X
0 2008-08-08 00:00:00.000 1
1 2008-08-08 00:00:00.001 2
2 2008-08-08 00:00:00.002 3
Date Operations#
Sometimes it is useful to get date (just year, month and day) from datetime
object, it can be done with date
method of otp.datetime
or via
otp.date
construction.
2019-01-01 17:08:00
2019-01-01
2019-01-01
True