Implement time module
Opened this issue · 2 comments
martinthenext commented
Currently, daytobase shows record time stamps in UTC. Instead, we have to query and record user's timezone and use it to:
- Convert UTC time stamps to user's timezone when outputting information
- Interpret time tags (
#t 12:04 pm
) and output UTC time stamps
Looks like PyMongo suggests we use pytz module. We need to:
- Figure out how to serialize/deserialize timezone objects to store them in MongoDB. Let us assume timezone is going to be defined by a string.
- Write functions that convert from a string representation to pytz timezone object and back
- Write a function
get_datetime_repr(dt, user)
wheredt
is a UTC datetime anduser
in an object that has atimezone
field with a timezone string representation in it, that outputs a string representation ofdt
in the right timezone. - Write a function
get_time_tag(message, user)
wheremessage
is a text of a message, i.e. "ate a banana #t one hour ago", and outputs adatetime
object in UTC.
For the latter, use cases we definitely need to handle:
- "#t 2016.08.23 18:32 flight to London" - we already handle that
#t one hour ago
#t 12:44
After that is done it would be nice to have at least some minor unittests for these functions.
jeremiecoullon commented
Just did the first 3 items:
pytz.all_timzones
lists the string representations of all timezoneslondon_tz = pytz.timezone("Europe/London")
converts from a string representation to a timezone object.london_tz.zone
converts back to the string representation- Wrote the
get_datetime_repr()
function intimezone_conversions.py
along with a very basic test (this is also just to get some tests set up which makes it easier to add more!)
jeremiecoullon commented
Merged this module into the dev
branch. I also renamed it timezone.py
(like Django's module), as time.py
clashed with the builtin time
module.