Skip to content

Commit

Permalink
Add Arrow DST tests based on two false positives (#747)
Browse files Browse the repository at this point in the history
* added Arrow DST tests based on two false positive open issues

* tests for dst

* Add comments explaining the new tests

* Move comments to docstring, rename test class

Co-authored-by: Mark Fonte <mark@fonte.com>
  • Loading branch information
2 people authored and jadchaar committed Jan 2, 2020
1 parent b12f4a6 commit 379e08f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/index.rst
Expand Up @@ -163,7 +163,7 @@ Format
Convert
~~~~~~~

Convert to timezones by name or tzinfo:
Convert from UTC to other timezones by name or tzinfo:

.. code-block:: python
Expand Down
52 changes: 52 additions & 0 deletions tests/arrow_tests.py
Expand Up @@ -512,6 +512,58 @@ def test_strftime(self):
self.assertEqual(result, self.arrow._datetime.strftime("%Y"))


class ArrowFalsePositiveDstTests(Chai):
"""These tests relate to issues #376 and #551.
The key points in both issues are that arrow will assign a UTC timezone if none is provided and
.to() will change other attributes to be correct whereas .replace() only changes the specified attribute.
Issue 376
>>> arrow.get('2016-11-06').to('America/New_York').ceil('day')
< Arrow [2016-11-05T23:59:59.999999-04:00] >
Issue 551
>>> just_before = arrow.get('2018-11-04T01:59:59.999999')
>>> just_before
2018-11-04T01:59:59.999999+00:00
>>> just_after = just_before.shift(microseconds=1)
>>> just_after
2018-11-04T02:00:00+00:00
>>> just_before_eastern = just_before.replace(tzinfo='US/Eastern')
>>> just_before_eastern
2018-11-04T01:59:59.999999-04:00
>>> just_after_eastern = just_after.replace(tzinfo='US/Eastern')
>>> just_after_eastern
2018-11-04T02:00:00-05:00
"""

def setUp(self):

super(ArrowFalsePositiveDstTests, self).setUp()
self.before_1 = arrow.Arrow(
2016, 11, 6, 3, 59, tzinfo=tz.gettz("America/New_York")
)
self.before_2 = arrow.Arrow(2016, 11, 6, tzinfo=tz.gettz("America/New_York"))
self.after_1 = arrow.Arrow(2016, 11, 6, 4, tzinfo=tz.gettz("America/New_York"))
self.after_2 = arrow.Arrow(
2016, 11, 6, 23, 59, tzinfo=tz.gettz("America/New_York")
)
self.before_3 = arrow.Arrow(
2018, 11, 4, 3, 59, tzinfo=tz.gettz("America/New_York")
)
self.before_4 = arrow.Arrow(2018, 11, 4, tzinfo=tz.gettz("America/New_York"))
self.after_3 = arrow.Arrow(2018, 11, 4, 4, tzinfo=tz.gettz("America/New_York"))
self.after_4 = arrow.Arrow(
2018, 11, 4, 23, 59, tzinfo=tz.gettz("America/New_York")
)

def test_dst(self):

self.assertEqual(self.before_1.day, self.before_2.day)
self.assertEqual(self.after_1.day, self.after_2.day)
self.assertEqual(self.before_3.day, self.before_4.day)
self.assertEqual(self.after_3.day, self.after_4.day)


class ArrowConversionTests(Chai):
def test_to(self):

Expand Down

0 comments on commit 379e08f

Please sign in to comment.