Compare commits

...

38 Commits

Author SHA1 Message Date
kennethreitz 8af92bc33c fixes #19 2016-12-20 12:20:50 -05:00
kennethreitz 917420071f v0.1.2 2016-12-20 12:15:01 -05:00
kennethreitz 2bb430b91d make setup.py python 2/3 compatible 2016-12-20 12:14:48 -05:00
kennethreitz 967638228a -e . 2016-12-20 12:12:59 -05:00
kennethreitz 1ba2dac284 Merge pull request #23 from aaronjeline/master
setup.py fix
2016-12-20 12:12:04 -05:00
Aaron Eline 89a54abf1f Added fix from @joaoleveiga 2016-12-20 09:56:00 -05:00
Aaron Eline f119fe927b Fixed missing comma in setup.py 2016-12-20 09:53:51 -05:00
kennethreitz 8b6ca639cb Merge pull request #21 from Factr/master
Python files executable, ruamel.yaml required
2016-12-19 13:29:32 -08:00
Adam Nelson 48c245a8ad Python files executable, ruamel.yaml required 2016-12-19 16:22:22 -05:00
kennethreitz 29a5b990fd day_first in tests 2016-12-19 13:31:03 -05:00
kennethreitz 69c88552d7 day_first 2016-12-19 13:02:47 -05:00
kennethreitz 2126c8f33e Merge pull request #20 from jerry2yu/master
Add datafirst parameter to parse method. Set datafirst true to parse …
2016-12-19 10:01:31 -08:00
kennethreitz dbc20b3026 Merge pull request #18 from harshit98/master
Update README.rst
2016-12-19 09:49:19 -08:00
Jerry Yu c521672f0e Add datafirst parameter to parse method. Set datafirst true to parse the first value in date (e.g. 01/05/2016) as the day 2016-12-19 13:00:18 -04:00
Harshit Prasad f756b13d4d Update README.rst 2016-12-19 21:01:07 +05:30
kennethreitz 2ce5a23e38 Merge pull request #16 from andrewthehan/typoReadme
Fix typo in README.rst
2016-12-18 21:37:03 -08:00
Andrew Han 605e15ae27 Fix typo in README.rst 2016-12-18 20:10:00 -08:00
kennethreitz 07a3e814a2 Update README.rst 2016-12-18 16:49:37 -05:00
kennethreitz 2e811d8689 Update README.rst 2016-12-18 16:47:28 -05:00
kennethreitz cbbd7d92c1 Update README.rst 2016-12-18 16:45:59 -05:00
kennethreitz d9e08034dd Update README.rst 2016-12-18 16:29:14 -05:00
kennethreitz e3b1eacb77 fix datetime formatting 2016-12-18 13:09:21 -05:00
kennethreitz be29d01160 Merge branch 'master' of github.com:kennethreitz/maya 2016-12-18 12:43:02 -05:00
kennethreitz 5e4853936b Merge pull request #8 from timofurrer/bugfix/format
Fix formatting MayaDT object
2016-12-18 09:41:58 -08:00
kennethreitz 7dbe450c28 Merge pull request #12 from djrobstep/bugfix/py-modules
my_modules -> py_modules
2016-12-18 09:41:29 -08:00
kennethreitz 3ce6734a5e Merge pull request #13 from grigouze/add_tests_for_coverage
Just add some tests to have full coverage
2016-12-18 09:41:12 -08:00
kennethreitz 6e2f530207 Merge pull request #7 from Kraymer/patch-1
Update README.rst (typo)
2016-12-18 09:40:04 -08:00
Grigouze c46d9874d4 Just add some tests to have full coverage
Now it's 💯 % coverage, i don't if it's good or bad but it was easy :)
2016-12-18 15:12:02 +01:00
Robert Lechte 87013d71e0 my_modules -> py_modules 2016-12-18 22:38:40 +11:00
Timo Furrer a562f48e24 Fix formatting MayaDT object 2016-12-18 10:59:22 +01:00
Fabrice Laporte 8fc07b3ab3 Update README.rst
Typo tomorrrow => tomorrow
2016-12-18 10:39:43 +01:00
kennethreitz 59064a5c50 Merge pull request #5 from uranusjr/master
Fix typos in README and add pip install instruction
2016-12-18 00:58:43 -08:00
Tzu-ping Chung 7ae84f3266 Add pip install instruction 2016-12-18 16:04:23 +08:00
Tzu-ping Chung cc668974b6 Fix typos 2016-12-18 16:03:35 +08:00
kennethreitz 6a4ddff215 Update README.rst 2016-12-18 02:48:45 -05:00
kennethreitz a0ab4fc3fb Update README.rst 2016-12-18 02:48:29 -05:00
kennethreitz c80ecad67b Update README.rst 2016-12-18 02:48:12 -05:00
kennethreitz 97842c01b3 Update README.rst 2016-12-18 02:47:57 -05:00
5 changed files with 83 additions and 16 deletions
+23 -6
View File
@@ -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
---------------------
@@ -30,7 +33,7 @@ Behold, datetimes for humans!
>>> tomorrow.iso8601()
'2016-12-16T15:11:30.263350Z'
>>> tomorrrow.rfc2822()
>>> tomorrow.rfc2822()
'Fri, 16 Dec 2016 20:11:30 -0000'
>>> tomorrow.datetime()
@@ -52,18 +55,27 @@ Behold, datetimes for humans!
>>> rand_day.timezone
UTC
☤ Why is this useful?
---------------------
- All timezone algebra will behave identically on all machines, regardless of system locale.
- Complete symmetric import and export of both ISO 8601 and RFC 2822 datetime stamps.
- Fantastic parsing of both dates written for/by humans and machines (``maya.when()`` vs ``maya.parse()``).
- Support for human slang, both import and export (e.g. `an hour ago`).
- Datetimes can very easily be generated, with our without tzinfo attached.
- Support for human slang, both import and export (e.g. `an hour ago`).
- Datetimes can very easily be generated, with or without tzinfo attached.
- This library is based around epoch time, but dates before Jan 1 1970 are indeed supported, via negative integers.
- Maya never panics, and always carrys a towel.
- 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
-----------------
@@ -73,3 +85,8 @@ Installation is easy, with pip::
$ pip install maya
✨🍰✨
☤ Like it?
----------
`Say Thanks <https://saythanks.io/to/kennethreitz>`_!
Regular → Executable
+10 -5
View File
@@ -34,7 +34,7 @@ class MayaDT(object):
def __format__(self, *args, **kwargs):
"""Return's the datetime's format"""
return self.datetime(*args, **kwargs)
return format(self.datetime(), *args, **kwargs)
# Timezone Crap
# -------------
@@ -104,12 +104,16 @@ class MayaDT(object):
dt = self.datetime().astimezone(pytz.timezone(to_timezone))
else:
dt = Datetime.utcfromtimestamp(self._epoch)
dt.replace(tzinfo=self._tz)
# Strip the timezone info if requested to do so.
if naive:
return dt.replace(tzinfo=None)
else:
if dt.tzinfo is None:
dt = dt.replace(tzinfo=self._tz)
return dt.replace(tzinfo=self._tz)
return dt
def iso8601(self):
"""Returns an ISO 8601 representation of the MayaDT."""
@@ -196,13 +200,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)
return MayaDT.from_datetime(dt)
dt = dateutil.parser.parse(string, dayfirst=day_first)
return MayaDT.from_datetime(dt)
+1
View File
@@ -1,3 +1,4 @@
-e .
dateparser==0.5.0
humanize==0.5.1
iso8601==0.1.11
Regular → Executable
+17 -4
View File
@@ -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,18 +28,19 @@ 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',
my_modules=['maya'],
py_modules=['maya'],
install_requires=required,
license='MIT',
classifiers=(
Regular → Executable
+32 -1
View File
@@ -1,3 +1,6 @@
import pytest
from datetime import datetime
import maya
@@ -43,10 +46,27 @@ def test_dt_tz_naive():
def test_random_date():
d = maya.when('11-17-11')
d = maya.when('11-17-11 08:09:10')
assert d.year == 2011
assert d.month == 11
assert d.day == 17
assert d.hour == 8
assert d.minute == 9
assert d.second == 10
assert d.microsecond == 0
def test_print_date(capsys):
d = maya.when('11-17-11')
print(d)
out, err = capsys.readouterr()
assert out == '<MayaDT epoch=1321488000.0>\n'
def test_invalid_date():
with pytest.raises(ValueError):
d = maya.when('another day')
def test_slang_date():
@@ -58,4 +78,15 @@ def test_slang_time():
d = maya.when('one hour ago')
assert d.slang_time() == 'an hour ago'
def test_format():
d = maya.parse('February 21, 1994')
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')