|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
| 3 | +import pendulum |
3 | 4 | from pendulum import Pendulum |
| 5 | +from pendulum.tz.exceptions import NonExistingTime |
4 | 6 |
|
5 | 7 | from .. import AbstractTestCase |
6 | 8 |
|
@@ -146,3 +148,34 @@ def test_with_timestamp(self): |
146 | 148 |
|
147 | 149 | self.assertIsInstanceOfPendulum(new) |
148 | 150 | self.assertPendulum(new, 1970, 1, 1, 0, 0, 0) |
| 151 | + |
| 152 | + def test_replace_tzinfo(self): |
| 153 | + d = Pendulum.create(2016, 7, 2, 0, 41, 20) |
| 154 | + new = d.replace(tzinfo='Europe/Paris') |
| 155 | + |
| 156 | + self.assertEqual(new.timezone_name, 'Europe/Paris') |
| 157 | + |
| 158 | + def test_replace_tzinfo_dst(self): |
| 159 | + d = Pendulum.create(2013, 3, 31, 2, 30) |
| 160 | + new = d.replace(tzinfo='Europe/Paris') |
| 161 | + |
| 162 | + self.assertPendulum(new, 2013, 3, 31, 3, 30) |
| 163 | + self.assertTrue(new.is_dst) |
| 164 | + self.assertEqual(new.offset, 7200) |
| 165 | + self.assertEqual(new.timezone_name, 'Europe/Paris') |
| 166 | + |
| 167 | + def test_replace_tzinfo_dst_with_pre_transition_rule(self): |
| 168 | + Pendulum.set_transition_rule(pendulum.PRE_TRANSITION) |
| 169 | + d = Pendulum.create(2013, 3, 31, 2, 30) |
| 170 | + new = d.replace(tzinfo='Europe/Paris') |
| 171 | + |
| 172 | + self.assertPendulum(new, 2013, 3, 31, 2, 30) |
| 173 | + self.assertFalse(new.is_dst) |
| 174 | + self.assertEqual(new.offset, 3600) |
| 175 | + self.assertEqual(new.timezone_name, 'Europe/Paris') |
| 176 | + |
| 177 | + def test_replace_tzinfo_dst_with_error_transition_rule(self): |
| 178 | + Pendulum.set_transition_rule(pendulum.TRANSITION_ERROR) |
| 179 | + d = Pendulum.create(2013, 3, 31, 2, 30) |
| 180 | + |
| 181 | + self.assertRaises(NonExistingTime, d.replace, tzinfo='Europe/Paris') |
0 commit comments