Skip to content

Commit

Permalink
use UTC values for msdos timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Jun 27, 2022
1 parent 38c9aff commit 9eda673
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 10 additions & 7 deletions src/Util/MsDosTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/util.msdostime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 9eda673

Please sign in to comment.