From 9eda673c09ebc32137c4d3f7aa112c6ab1b51336 Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Mon, 27 Jun 2022 14:08:43 +0200 Subject: [PATCH] use UTC values for msdos timestamps --- package.json | 2 +- src/Util/MsDosTime.js | 17 ++++++++++------- test/util.msdostime.test.js | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 71f3db3..60f1fdd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "armarius", - "version": "1.3.7", + "version": "1.3.8", "description": "A JavaScript library to read, write, and merge ZIP archives in web browsers.", "repository": "github:aternosorg/armarius", "type": "module", diff --git a/src/Util/MsDosTime.js b/src/Util/MsDosTime.js index 9e63810..85fe78e 100644 --- a/src/Util/MsDosTime.js +++ b/src/Util/MsDosTime.js @@ -11,9 +11,9 @@ export default class MsDosTime { static encodeTime(date) { date = this.clampDate(date); let res = 0; - res |= Math.floor(date.getSeconds() / 2) & 0b11111; - res |= (date.getMinutes() & 0b111111) << 5; - res |= (date.getHours() & 0b11111) << 11; + res |= Math.floor(date.getUTCSeconds() / 2) & 0b11111; + res |= (date.getUTCMinutes() & 0b111111) << 5; + res |= (date.getUTCSeconds() & 0b11111) << 11; return res; } @@ -26,9 +26,9 @@ export default class MsDosTime { static encodeDate(date) { date = this.clampDate(date); let res = 0; - res |= date.getDate() & 0b11111; - res |= ((date.getMonth() + 1) & 0b1111) << 5; - res |= ((date.getFullYear() - 1980) & 0b1111111) << 9; + res |= date.getUTCDate() & 0b11111; + res |= ((date.getUTCMonth() + 1) & 0b1111) << 5; + res |= ((date.getUTCFullYear() - 1980) & 0b1111111) << 9; return res; } @@ -45,7 +45,10 @@ export default class MsDosTime { month = ((date >> 5) & 0b1111) + 1, year = (date >> 9) + 1980; - return new Date(year, month, day, hours, minutes, seconds, 0); + let res = new Date(); + res.setUTCFullYear(year, month, day); + res.setUTCHours(hours, minutes, seconds, 0); + return res; } /** diff --git a/test/util.msdostime.test.js b/test/util.msdostime.test.js index daaac3f..522d3ba 100644 --- a/test/util.msdostime.test.js +++ b/test/util.msdostime.test.js @@ -4,7 +4,7 @@ const timestamp = 1655914036349; const roundedTimestamp = 1661184436000; const date = new Date(timestamp); -let timeValue = 37096; +let timeValue = 33000; let dateValue = 21718; test('Encode date value', () => {