mirror of
https://github.com/kennethreitz/maya.git
synced 2026-06-05 23:00:18 +00:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 917420071f | |||
| 2bb430b91d | |||
| 967638228a | |||
| 1ba2dac284 | |||
| 89a54abf1f | |||
| f119fe927b | |||
| 8b6ca639cb | |||
| 48c245a8ad | |||
| 29a5b990fd | |||
| 69c88552d7 | |||
| 2126c8f33e | |||
| dbc20b3026 | |||
| c521672f0e | |||
| f756b13d4d | |||
| 2ce5a23e38 | |||
| 605e15ae27 | |||
| 07a3e814a2 | |||
| 2e811d8689 | |||
| cbbd7d92c1 | |||
| d9e08034dd | |||
| e3b1eacb77 |
+14
-2
@@ -8,6 +8,9 @@ simple things **much** easier, while admitting that time is an illusion
|
||||
|
||||
Datetimes should be interacted with via an API written for humans.
|
||||
|
||||
Maya is mostly built around the headaches and use-cases around parsing datetime data from websites.
|
||||
|
||||
|
||||
☤ Basic Usage of Maya
|
||||
---------------------
|
||||
|
||||
@@ -52,8 +55,6 @@ Behold, datetimes for humans!
|
||||
>>> rand_day.timezone
|
||||
UTC
|
||||
|
||||
|
||||
|
||||
☤ Why is this useful?
|
||||
---------------------
|
||||
|
||||
@@ -65,6 +66,17 @@ Behold, datetimes for humans!
|
||||
- This library is based around epoch time, but dates before Jan 1 1970 are indeed supported, via negative integers.
|
||||
- Maya never panics, and always carries a towel.
|
||||
|
||||
|
||||
☤ What about Delorean, Arrow, & Pendulum?
|
||||
-----------------------------------------
|
||||
|
||||
Arrow, for example, is a fantastic library, but isn't what I wanted in a datetime library. In many ways, it's better than Maya for certain things. In some ways, in my opinion, it's not.
|
||||
|
||||
I simply desire a sane API for datetimes that made sense to me for all the things I'd ever want to do—especially when dealing with timezone algebra. Arrow doesn't do all of the things I need (but it does a lot more!). Maya does do exactly what I need.
|
||||
|
||||
I think these projects complement each-other, personally. Maya is great for parsing websites. For example- Arrow supports floors and ceilings and spans of dates, which Maya does not at all.
|
||||
|
||||
|
||||
☤ Installing Maya
|
||||
-----------------
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class MayaDT(object):
|
||||
|
||||
def __format__(self, *args, **kwargs):
|
||||
"""Return's the datetime's format"""
|
||||
return format(self.datetime(*args, **kwargs))
|
||||
return format(self.datetime(), *args, **kwargs)
|
||||
|
||||
# Timezone Crap
|
||||
# -------------
|
||||
@@ -196,13 +196,14 @@ def when(string, timezone='UTC'):
|
||||
|
||||
return MayaDT.from_datetime(dt)
|
||||
|
||||
def parse(string):
|
||||
def parse(string, day_first=False):
|
||||
""""Returns a MayaDT instance for the machine-produced moment specified.
|
||||
|
||||
Powered by dateutil. Accepts most known formats. Useful for working with data.
|
||||
|
||||
Keyword Arguments:
|
||||
string -- string to be parsed
|
||||
day_first -- if true, the first value (e.g. 01/05/2016) is parsed as day (default: False)
|
||||
"""
|
||||
dt = dateutil.parser.parse(string)
|
||||
dt = dateutil.parser.parse(string, dayfirst=day_first)
|
||||
return MayaDT.from_datetime(dt)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
-e .
|
||||
dateparser==0.5.0
|
||||
humanize==0.5.1
|
||||
iso8601==0.1.11
|
||||
|
||||
@@ -3,9 +3,21 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import codecs
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
try:
|
||||
# Python 3
|
||||
from os import dirname
|
||||
except ImportError:
|
||||
# Python 2
|
||||
from os.path import dirname
|
||||
|
||||
here = os.path.abspath(dirname(__file__))
|
||||
|
||||
def read(*parts):
|
||||
return codecs.open(os.path.join(here, *parts), 'r').read()
|
||||
|
||||
if sys.argv[-1] == "publish":
|
||||
os.system("python setup.py sdist bdist_wheel upload")
|
||||
@@ -16,14 +28,15 @@ required = [
|
||||
'pytz',
|
||||
'dateparser',
|
||||
'iso8601',
|
||||
'python-dateutil'
|
||||
'python-dateutil',
|
||||
'ruamel.yaml'
|
||||
]
|
||||
|
||||
setup(
|
||||
name='maya',
|
||||
version='0.1.0',
|
||||
version='0.1.2',
|
||||
description='Datetimes for Humans.',
|
||||
long_description=open('README.rst').read(),
|
||||
long_description= '\n' + read('README.rst'),
|
||||
author='Kenneth Reitz',
|
||||
author_email='me@kennethreitz.com',
|
||||
url='https://github.com/kennethreitz/maya',
|
||||
|
||||
Regular → Executable
+7
-3
@@ -63,8 +63,6 @@ def test_print_date(capsys):
|
||||
out, err = capsys.readouterr()
|
||||
assert out == '<MayaDT epoch=1321488000.0>\n'
|
||||
|
||||
assert type(d.__format__()) is datetime
|
||||
|
||||
|
||||
def test_invalid_date():
|
||||
with pytest.raises(ValueError):
|
||||
@@ -83,6 +81,12 @@ def test_slang_time():
|
||||
|
||||
def test_format():
|
||||
d = maya.parse('February 21, 1994')
|
||||
assert format(d) == format(d.datetime())
|
||||
assert format(d) == '1994-02-21 00:00:00+00:00'
|
||||
|
||||
d = maya.parse('01/05/2016')
|
||||
assert format(d) == '2016-01-05 00:00:00+00:00'
|
||||
|
||||
d = maya.parse('01/05/2016', day_first=True)
|
||||
assert format(d) == '2016-05-01 00:00:00+00:00'
|
||||
|
||||
# rand_day = maya.when('2011-02-07', timezone='US/Eastern')
|
||||
|
||||
Reference in New Issue
Block a user