mirror of
https://github.com/kennethreitz/maya.git
synced 2026-06-05 23:00:18 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77e6249287 | |||
| 5525beda31 | |||
| eeb07d46db | |||
| 4056d1a9aa | |||
| 7a750a1cff | |||
| bc06315abd |
@@ -1,4 +1,8 @@
|
|||||||
language: python
|
language: python
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
- osx
|
||||||
|
|
||||||
python:
|
python:
|
||||||
- "2.7"
|
- "2.7"
|
||||||
- "3.6"
|
- "3.6"
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
__version__ = '0.4.0'
|
__version__ = '0.4.2'
|
||||||
|
|||||||
@@ -257,6 +257,14 @@ class MayaDT(object):
|
|||||||
dt = dt.replace(tzinfo=self._tz)
|
dt = dt.replace(tzinfo=self._tz)
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
|
def local_datetime(self):
|
||||||
|
"""Returns a local timezone-aware datetime object
|
||||||
|
|
||||||
|
It's the same as:
|
||||||
|
mayaDt.datetime(to_timezone=mayaDt.local_timezone)
|
||||||
|
"""
|
||||||
|
return self.datetime(to_timezone=self.local_timezone, naive=False)
|
||||||
|
|
||||||
def iso8601(self):
|
def iso8601(self):
|
||||||
"""Returns an ISO 8601 representation of the MayaDT."""
|
"""Returns an ISO 8601 representation of the MayaDT."""
|
||||||
# Get a timezone-naive datetime.
|
# Get a timezone-naive datetime.
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ required = [
|
|||||||
'pytz',
|
'pytz',
|
||||||
'dateparser>=0.7.0',
|
'dateparser>=0.7.0',
|
||||||
'tzlocal',
|
'tzlocal',
|
||||||
'pendulum>=1.0',
|
'pendulum>=1.0, <=1.5.1',
|
||||||
'snaptime'
|
'snaptime'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -342,6 +342,28 @@ def test_core_local_timezone(monkeypatch):
|
|||||||
assert mdt.local_timezone == 'UTC'
|
assert mdt.local_timezone == 'UTC'
|
||||||
|
|
||||||
|
|
||||||
|
def test_getting_datetime_for_local_timezone(monkeypatch):
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mock_local_tz(self):
|
||||||
|
class StaticTzInfo(object):
|
||||||
|
zone = 'Europe/Zurich'
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<StaticTzInfo 'Europe/Zurich'>"
|
||||||
|
|
||||||
|
return StaticTzInfo()
|
||||||
|
|
||||||
|
monkeypatch.setattr(maya.MayaDT, '_local_tz', mock_local_tz)
|
||||||
|
|
||||||
|
d = maya.parse('1994-02-21T12:00:00+05:30')
|
||||||
|
|
||||||
|
dt = pytz.timezone('Europe/Zurich').localize(
|
||||||
|
Datetime(1994, 2, 21, 7, 30))
|
||||||
|
|
||||||
|
assert d.local_datetime() == dt
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("when_str,snap_str,expected_when", [
|
@pytest.mark.parametrize("when_str,snap_str,expected_when", [
|
||||||
('Mon, 21 Feb 1994 21:21:42 GMT', '@d',
|
('Mon, 21 Feb 1994 21:21:42 GMT', '@d',
|
||||||
'Mon, 21 Feb 1994 00:00:00 GMT'),
|
'Mon, 21 Feb 1994 00:00:00 GMT'),
|
||||||
|
|||||||
Reference in New Issue
Block a user