Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion dist/timezonecomplete.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/timezonecomplete.min.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/lib/tz-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,30 @@ export class TzDatabase {
return undefined;
}

/**
* Last DST change (moment AFTER) of the given UTC date in UTC milliseconds, within one year,
* returns undefined if no such change
* @throws timezonecomplete.NotFound.Zone if zone name not found or a linked zone not found
* @throws timezonecomplete.InvalidTimeZoneData if values in the time zone database are invalid
*/
public lastDstChange(zoneName: string, utcTime: number): number | undefined;
public lastDstChange(zoneName: string, utcTime: TimeStruct): number | undefined;
public lastDstChange(zoneName: string, a: TimeStruct | number): number | undefined {
const utcTime: TimeStruct = (typeof a === "number" ? new TimeStruct(a) : a);
const zone = this._getZoneTransitions(zoneName);
let iterator = zone.findFirst();
let lastChange: number | undefined;
while (iterator) {
if (iterator.transition.atUtc > utcTime) {
break;
}
lastChange = iterator.transition.atUtc.unixMillis;
iterator = zone.findNext(iterator);
}

return lastChange;
}

/**
* Returns true iff the given zone name eventually links to
* "Etc/UTC", "Etc/GMT" or "Etc/UCT" in the TZ database. This is true e.g. for
Expand Down
12 changes: 12 additions & 0 deletions src/test/test-tz-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,18 @@ describe("TzDatabase", (): void => {
});
});

describe("lastDstChange()", (): void => {
it("should return the last winter to summer time change", (): void => {
expect(TzDatabase.instance().lastDstChange("Europe/Amsterdam", new TimeStruct(1427590800001))).to.equal(1427590800000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjust the tests to be more readable (use ISO strings)

});
it("should return the last summer to winter time change", (): void => {
expect(TzDatabase.instance().lastDstChange("Europe/Amsterdam", new TimeStruct(1445734800001))).to.equal(1445734800000);
});
it("should work with AtType=Wall", (): void => {
expect(TzDatabase.instance().lastDstChange("America/Detroit", 1615701600000 + 3600000 + 1)).to.equal(1615701600000 + 3600000);
});
});

describe("normalizeLocal()", (): void => {
it("should not change dates outside DST changes", (): void => {
expect(TzDatabase.instance().normalizeLocal(
Expand Down