All Projects → dgilland → Zulu

dgilland / Zulu

Licence: mit
A drop-in replacement for native Python datetimes that embraces UTC.

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Zulu

Carbon
A simple, semantic and developer-friendly golang package for datetime
Stars: ✭ 565 (+986.54%)
Mutual labels:  time, date, datetime
Period
PHP's time range API
Stars: ✭ 616 (+1084.62%)
Mutual labels:  time, date, datetime
chronos
One library to rule the time
Stars: ✭ 17 (-67.31%)
Mutual labels:  time, datetime, date
Tinydate
A tiny (349B) reusable date formatter. Extremely fast!
Stars: ✭ 990 (+1803.85%)
Mutual labels:  time, date, datetime
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (-53.85%)
Mutual labels:  time, datetime, date
dt
Go's missing DateTime package
Stars: ✭ 34 (-34.62%)
Mutual labels:  time, datetime, date
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (-44.23%)
Mutual labels:  time, datetime, date
rutimeparser
Recognize date and time in russian text and return datetime.datetime.
Stars: ✭ 17 (-67.31%)
Mutual labels:  time, datetime, date
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-30.77%)
Mutual labels:  time, datetime, date
nepali-datetime
Python's core datetime inspired nepali datetime (BS date & NPT) package 🇳🇵
Stars: ✭ 36 (-30.77%)
Mutual labels:  time, datetime, date
Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (+930.77%)
Mutual labels:  time, date, datetime
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+71771.15%)
Mutual labels:  time, date, datetime
Pendulum
Python datetimes made easy
Stars: ✭ 4,639 (+8821.15%)
Mutual labels:  time, date, datetime
shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (+13.46%)
Mutual labels:  time, datetime, date
hs-hourglass
efficient and simpler time API for haskell
Stars: ✭ 43 (-17.31%)
Mutual labels:  time, datetime, date
rescript-date
📆 Date manipulation in ReScript.
Stars: ✭ 101 (+94.23%)
Mutual labels:  time, datetime, date
date-extractor
Extract dates from text
Stars: ✭ 58 (+11.54%)
Mutual labels:  time, datetime, date
qrono
🕥 Just right date time library
Stars: ✭ 111 (+113.46%)
Mutual labels:  time, datetime, date
vue-timeselector
🕒 Simply customizable powerful time picker for Vue.js
Stars: ✭ 41 (-21.15%)
Mutual labels:  time, datetime, date
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (+465.38%)
Mutual labels:  time, date, datetime

zulu


|version| |build| |coveralls| |license|

A drop-in replacement for native datetimes that embraces UTC

Links

Features

  • All datetime objects converted and stored as UTC.
  • Parses ISO8601 formatted strings and POSIX timestamps by default.
  • Timezone representation applied only during string output formatting or when casting to native datetime object.
  • Drop-in replacement for native datetime objects.
  • Python 3.6+

Quickstart

Install using pip:

::

pip3 install zulu

.. code-block:: python

import zulu

zulu.now()
# <Zulu [2016-07-25T19:33:18.137493+00:00]>

dt = zulu.parse('2016-07-25T19:33:18.137493+00:00')
# <Zulu [2016-07-25T19:33:18.137493+00:00]>

dt = zulu.create(2016, 7, 25, 19, 33, 18, 137493)
# <Zulu [2016-07-25T19:33:18.137493+00:00]>

dt.isoformat()
# '2016-07-25T19:33:18.137493+00:00'

dt.timestamp()
# 1469475198.137493

dt.naive
# datetime.datetime(2016, 7, 25, 19, 33, 18, 137493)

dt.datetime
# datetime.datetime(2016, 7, 25, 19, 33, 18, 137493, tzinfo=<UTC>)

dt.format('%Y-%m-%d')
# 2016-07-25

dt.format('YYYY-MM-dd')
# 2016-07-25

dt.format("E, MMM d, ''YY")
# "Mon, Jul 25, '16"

dt.format("E, MMM d, ''YY", locale='de')
# "Mo., Juli 25, '16"

dt.format("E, MMM d, ''YY", locale='fr')
# "lun., juil. 25, '16"

dt.shift(hours=-5, minutes=10)
# <Zulu [2016-07-25T14:43:18.137493+00:00]>

dt.replace(hour=14, minute=43)
# <Zulu [2016-07-25T14:43:18.137493+00:00]>

dt.start_of('day')
# <Zulu [2016-07-25T00:00:00+00:00]>

dt.end_of('day')
# <Zulu [2016-07-25T23:59:59.999999+00:00]>

dt.span('hour')
# (<Zulu [2016-07-25T19:00:00+00:00]>, <Zulu [2016-07-25T19:59:59.999999+00:00]>)

dt.time_from(dt.end_of('day'))
# '4 hours ago'

dt.time_to(dt.end_of('day'))
# 'in 4 hours'

list(zulu.range('hour', dt, dt.shift(hours=4)))
# [Zulu [2016-07-25T19:33:18.137493+00:00]>,
#  Zulu [2016-07-25T20:33:18.137493+00:00]>,
#  Zulu [2016-07-25T21:33:18.137493+00:00]>,
#  Zulu [2016-07-25T22:33:18.137493+00:00]>]

list(zulu.span_range('minute', dt, dt.shift(minutes=4)))
# [(Zulu [2016-07-25T19:33:00+00:00]>, Zulu [2016-07-25T19:33:59.999999+00:00]>),
#  (Zulu [2016-07-25T19:34:00+00:00]>, Zulu [2016-07-25T19:34:59.999999+00:00]>),
#  (Zulu [2016-07-25T19:35:00+00:00]>, Zulu [2016-07-25T19:35:59.999999+00:00]>),
#  (Zulu [2016-07-25T19:36:00+00:00]>, Zulu [2016-07-25T19:36:59.999999+00:00]>)]

zulu.parse_delta('1w 3d 2h 32m')
# <Delta [10 days, 2:32:00]>

zulu.parse_delta('2:04:13:02.266')
# <Delta [2 days, 4:13:02.266000]>

zulu.parse_delta('2 days, 5 hours, 34 minutes, 56 seconds')
# <Delta [2 days, 5:34:56]>

Why Zulu?

Why zulu instead of native datetimes <https://docs.python.org/3.5/library/datetime.html#datetime-objects>_:

  • Zulu has extended datetime features such as parse(), format(), shift(), and python-dateutil_ timezone support.
  • Parses ISO8601 and timestamps by default without any extra arguments.
  • Easier to reason about Zulu objects since they are only ever UTC datetimes.
  • Clear delineation between UTC and other time zones where timezone representation is only applicable for display or conversion to native datetime.
  • Supports more string parsing/formatting options using Unicode date patterns_ as well as strptime/strftime directives.

Why zulu instead of Arrow_:

  • Zulu is a drop-in replacement for native datetimes (inherits from datetime.datetime). No need to convert using arrow.datetime when you need a datetime (zulu is always a datetime).
  • Stricter parsing to avoid silent errors. For example, one might expect arrow.get('02/08/1987', 'MM/DD/YY') to fail (input does not match format) but it gladly returns <Arrow [2019-02-08T00:00:00+00:00) whereas zulu.parse('02/08/1987', '%m/%d/%y') throws zulu.parser.ParseError: Value "02/08/1987" does not match any format in ['%m/%d/%y'].
  • Avoids timezone/DST shifting bugs by only dealing with UTC datetimes when applying timedeltas or performing other calculations.
  • Supports strptime/strftime as well as Unicode date patterns_ for string parsing/formatting.

Special Thanks

Special thanks goes out to the authors/contributors of the following libraries that have made it possible for zulu to exist:

  • Babel_
  • iso8601_
  • python-dateutil_
  • pytimeparse_
  • pytz_

For the full documentation, please visit https://zulu.readthedocs.io.

.. _Unicode date patterns: http://www.unicode.org/reports/tr35/tr35-19.html#Date_Field_Symbol_Table .. _Arrow: https://arrow.readthedocs.io .. _Babel: https://github.com/python-babel/babel .. _iso8601: https://bitbucket.org/micktwomey/pyiso8601 .. _python-dateutil: https://github.com/dateutil/dateutil .. _pytimeparse: https://github.com/wroberts/pytimeparse .. _pytz: http://pythonhosted.org/pytz

.. |version| image:: https://img.shields.io/pypi/v/zulu.svg?style=flat-square :target: https://pypi.python.org/pypi/zulu/

.. |build| image:: https://img.shields.io/github/workflow/status/dgilland/zulu/Main/master?style=flat-square :target: https://github.com/dgilland/zulu/actions

.. |coveralls| image:: https://img.shields.io/coveralls/dgilland/zulu/master.svg?style=flat-square :target: https://coveralls.io/r/dgilland/zulu

.. |license| image:: https://img.shields.io/pypi/l/zulu.svg?style=flat-square :target: https://pypi.python.org/pypi/zulu/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].