Skip to content

Commit 5b7746a

Browse files
kz930claude
andcommitted
feat(amber): read an offset before 1900 at the zone's standard offset, as the engine does
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 72dcf19 commit 5b7746a

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎amber/src/main/python/core/models/schema/attribute_type.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,25 @@ def _local_wall_clock(moment):
121121
# The wall clock the machine's zone shows at an instant that states its
122122
# offset. Windows' localtime refuses an instant before 1970, so the zone is
123123
# asked by name where it has one, and otherwise such an instant takes the
124-
# machine's standard offset.
124+
# machine's standard offset. Before 1900 the engine reads every zone at
125+
# its standard offset, where a named zone would give its local mean time.
125126
zone = _named_local_zone()
127+
utc = moment.astimezone(datetime.timezone.utc).replace(tzinfo=None)
128+
if utc < datetime.datetime(1900, 1, 1):
129+
return utc + _standard_offset(zone)
126130
if zone is not None:
127131
return moment.astimezone(zone).replace(tzinfo=None)
128132
try:
129133
return moment.astimezone().replace(tzinfo=None)
130134
except (OSError, OverflowError):
131-
utc = moment.astimezone(datetime.timezone.utc).replace(tzinfo=None)
132-
return utc - datetime.timedelta(seconds=time.timezone)
135+
return utc + _standard_offset(None)
136+
137+
138+
def _standard_offset(zone):
139+
if zone is None:
140+
return datetime.timedelta(seconds=-time.timezone)
141+
now = datetime.datetime.now(zone)
142+
return now.utcoffset() - now.dst()
133143

134144

135145
def _named_local_zone():

‎amber/src/test/python/core/models/schema/test_attribute_type.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,27 @@ def test_an_explicit_offset_is_moved_to_the_machine_zone(self, machine_zone):
130130
("3000-01-01T12:00:00Z", datetime.datetime(3000, 1, 1, 17, 30)),
131131
],
132132
)
133-
def test_an_offset_follows_the_named_zone_in_any_year(
133+
def test_an_offset_follows_the_named_zone_from_1900_on(
134134
self, machine_zone, text, expected
135135
):
136136
machine_zone("Asia/Kolkata")
137137
assert parse_timestamp(text) == expected
138138

139+
@pytest.mark.parametrize(
140+
"zone, expected",
141+
[
142+
("America/Mexico_City", datetime.datetime(1600, 1, 1, 6, 0)),
143+
("Asia/Kolkata", datetime.datetime(1600, 1, 1, 17, 30)),
144+
],
145+
)
146+
def test_an_offset_before_1900_takes_the_standard_offset(
147+
self, machine_zone, zone, expected
148+
):
149+
# The engine's DateParserUtils and Timestamp on JDK 17 give these,
150+
# where the zone's own rules would give its local mean time.
151+
machine_zone(zone)
152+
assert parse_timestamp("1600-01-01T12:00:00Z") == expected
153+
139154
@pytest.mark.parametrize(
140155
"text, expected",
141156
[

0 commit comments

Comments
 (0)