Giter VIP home page Giter VIP logo

zulu's People

Contributors

bharadwajyarlagadda avatar dgilland avatar thomaschiroux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zulu's Issues

zulu.format("YYYY") gives wrong wrong year

Hi, thanks for a great time library.

I'm facing a weird issue. When parsing a datetime string with 31.12 or 30.12 I get the wrong year when formatting as "YYYY"

To reproduce:
`

import zulu
zulu.parse("2019-12-31 00:00:00.000Z").format("YYYY")
'2020'
zulu.parse("2019-12-30 00:00:00.000Z").format("YYYY")
'2020'
zulu.parse("2019-12-29 00:00:00.000Z").format("YYYY")
'2019'
`

Should this really happen?

Make DateTime.parse/format understand Unicode date patterns

Arrow tokens: https://arrow.readthedocs.io/en/latest/#tokens
Unicode date patterns: http://www.unicode.org/reports/tr35/tr35-19.html#Date_Field_Symbol_Table

I think we can "cheat" a bit and simply map Arrow Unicode tokens to strptime-style tokens. Nothing fancy, perhaps just a simple look-ahead parser that translates things like YYYY-MM-DD into %Y-%m-%d or M/D/YY into %-m/%-d/%y (note that %-m and %-d require glibc installed so may need a more universal way to handle that or simply make note of it as a requirement).

Replace zulu.delta with zulu.parse_delta

It can lead to confusion between zulu.delta and zulu.Delta since these two have different parameters and handle positional arguments differently. So we'll rename zulu.delta to zulu.parse_delta to make it more explicit.

Support parsing a datetime/timedelta object from a dict

Allow user to do something like that following:

zulu.parse({'year': 2017, 'month': 2, 'day': 9})
zulu.parse(**{'year': 2017, 'month': 2, 'day': 9})

zulu.parse_delta({'hours': 1, 'minutes': 30, 'seconds': 15})
zulu.parse_delta(**{'hours': 1, 'minutes': 30, 'seconds': 15})

Add DateTime.days_in_year(), DateTime.days_in_years(), DateTime.days_in_months(), DateTime.weeks_in_year()

DateTime.days_in_year() --> Should return total number of days in a particular year.

DateTime.days_in_years() --> Should return total number of days in a given years range. For example, DateTime.days_in_years(2016, 2018) should return the total number of days from January 1st 2016 to December 31st 2018.

DateTime.days_in_months() --> Should return total number of days in a given month range. For example, DateTime.days_in_months(2, 5) should return the total number of days from February 1st to May 1st.

DateTime.weeks_in_year() --> We can use isocalendar() and return the number of weeks.

problems with python 3.8 in timezones

example from python 3.8

Python 3.8.1 (default, Jan  8 2020, 23:09:20)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.10.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from dateutil import tz

In [2]: import zulu

In [3]: n = zulu.now()

In [4]: n
Out[4]: <Zulu [2020-01-14T22:37:07.389997+00:00]>

In [5]: n.astimezone(tz.gettz("Europe/Paris"))
Out[5]: <Zulu [2020-01-14T22:37:07.389997+00:00]>

In [6]: n.datetime.astimezone(tz.gettz("Europe/Paris"))
Out[6]: datetime.datetime(2020, 1, 14, 23, 37, 7, 389997, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Paris'))

Also tried to update tox in a zulu fork and test branch: all unittests are OK in python 3.7 and less, but not ok in python 3.8:
https://travis-ci.com/ThomasChiroux/zulu/builds/144422588

This may have been related to this python bug:
https://bugs.python.org/issue32417 which has been merged in python 3.8

still investigating...
(a work around could be as seen in the example to call datetime before astimezone and force a cast to datetime before calling astimezone, but it's less powerfull than standard zulu lib (no timezone parsing)

Add DateTime.add and DateTime.sub methods

Should basically call DateTime.shift.

dt.add(hours=5) == dt.shift(hours=5)
dt.add(hours=-5) == dt.shift(hours=-5)
dt.sub(hours=5) == dt.shift(hours=-5)
dt.sub(hours=-5) == dt.shift(hours=5)

Add DateTime.days_in_month()

Should return the number of days in the current month of the DateTime object.

Can use calendar.monthrange:

>>> from calendar import monthrange
>>> monthrange(2011, 2)
(1, 28)
>>> monthrange(2012, 2)
(2, 29)

Add DateTime.get_days(), DateTime.get_weeks(), DateTime.get_weekday()

DateTime.get_days() --> Should return the total number of days between the given dates. For example, DateTime.get_days('05/23/2016', '06/23/2016') should return you the total number of days between those two dates.

DateTime.get_weeks() --> Same as get_days() but, this returns total number of weeks between the given dates.

DateTime.get_weekday() --> Should return a tuple something like (3, 'Wednesday') when a date is given. For example, DateTime.get_weekday('8/3/2016') should return (3, 'Wednesday') where 3 represents third day in the week.

Add "time from now", "time from X", "time to now", and "time to X"

Basically want to have something that works like this:

dt1 = DateTime(2015, 1, 1)
dt2 = DateTime(2017, 1, 1)

dt1.format_from_now()
# dt1 - now()
#1 year, 7 months ago

dt1.format_to_now()
# now() - dt1
# in 1 year, 7 months

dt1.format_from(dt2)
# dt1 - dt2
#2 years ago

dt1.format_to(dt2)
# dt2 - dt1
# in 2 years

dt2.format_from_now()
# dt2 - now()
# in 4 months

dt2.format_to_now()
# now() - dt2
#4 months ago

dt2.format_from(dt1)
# dt2 - dt1
# in 2 years

dt2.format_to(dt1)
# dt1 - dt2
#2 years ago

Can use babel.dates.format_timedelta.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.