Commit 66e595c
authored
[storage-file-datalake] [Bug Fix] Fix the date property(createdOn, expiresOn) in some of the returned responses (Azure#25072)
### Packages impacted by this PR
`@azure/storage-file-datalake`
### Issues associated with this PR
Fixes Azure#25068
### Describe the problem that is addressed by this PR
`windowsFileTimeTicksToTime` calculation somehow went wrong since 2023
with a 1-day difference, perhaps due to miscalculation w.r.t leap days.
This PR attempts to fix the bug and fix the tests.
The new implementation makes use of the JS Date object to do most of the
calculation instead of relying on the numbers/constants to account for
the leap days.
```js
// Existing Code - Straight from the storage-file-datalake code
function windowsFileTimeTicksToTime(timeNumber: string | undefined): Date | undefined {
if (!timeNumber) return undefined;
const timeNumberInternal = parseInt(timeNumber!);
if (timeNumberInternal === 0) return undefined;
const date = new Date(timeNumberInternal / 10000);
date.setUTCFullYear(date.getUTCFullYear() - 369);
return date;
}
// New Implementation - Alternative algo from stackoverflow that works as expected
// Reference https://stackoverflow.com/a/24188106
function windowsFileTimeTicksToTime2(timeNumber: string | undefined): Date | undefined {
if (!timeNumber) return undefined;
const timeElapsed = parseInt(timeNumber)/10000;
if (timeElapsed === 0) return undefined;
// Milliseconds calculated relative to "12:00 A.M. January 1, 1970" (will be negative)
const initialFrameOfReference = Date.UTC(1601, 0, 1);
// TimeRelativeTo1970 = (TimeAt1601 - TimeAt1970) + (Current - TimeAt1601) = (Current - TimeAt1970)
return new Date(initialFrameOfReference + timeElapsed);
}
// Value from a saved recording
const olderTicks = "132934495529749313"; // April 3rd, 2022
console.log(windowsFileTimeTicksToTime(olderTicks)) // "2022-04-03T08:52:32.974Z"
console.log(windowsFileTimeTicksToTime2(olderTicks)) // "2022-04-03T08:52:32.974Z"
// Current time (At about the time of this PR)
const newerTicks = "133222649014464202"; // March 2nd, 2023
console.log(windowsFileTimeTicksToTime(newerTicks)) // "2023-03-01T21:08:21.446Z"
console.log(windowsFileTimeTicksToTime2(newerTicks)) // "2023-03-02T21:08:21.446Z"
```
## Playground if you want to play with
[windows filetime to JS date - TS
playground](https://www.typescri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zPNSq8sBwCwJU5EIABye9QBpJQAuRep2B4CtWBkz5FDW+9NpJHbYyIYpPOHNAcgAUSZFlBhGMYJimLT1mgYJgFXXFqgu0BzTJf6NojbbSE5YgACJeWq2rkwapqM1a1UyeA867Oh2H4h2IYDhhY4KjOKorlKiGyWBeB2DUOA9AAeXQGj0Dorl4enQV93MBnFT2BUsUWMrQGFdbAcjT4eA+r7uphDgoMheCKfjGrEzqlNGrTZqs1zMmMgUR7HBbQhEG++lgk8n8TgnSaenMRRRfFyXCBluWFeIABqQKYaKlkdZucxzVuSB1dAF8c7z07ChT8x1TKYpugL3GWlz9XCiGcvK5WtBC7r4vcyDoDKNAAA1eaYzwb5+vpUla06-tQEEYWsErJwVPwoYKdfHlM1fP4-kzABWbe1+zLfXyxV8yex0C4QYN9oCYJUeT2HkeRnmQSDn7dMMQcw5KeRTGGUgwjBMOacwc8BDQEXiQYIhQcZkzvg-agewAR7FfFoPYwlnB72cKvQUOY-gAC0PZP0aK-QU79P6PAUhoX+LRwGAI0sA+eYD-4QMKDcGB98eTwMQcg1B6C+RYJwfg6evcK41lboFDIucvj2HLJDIg4jMQ+mCgABSooUQhTQJwLyYfDFeq8H7-EzKqTe-xYGnxxsKMYPBkCgB5EoW+99XzqOIaQr+FClLUKYbQiwmjGGqUgbrNhPJXzwOCaqLQPIsT8jQREwUxj8FOMYCQrAH9XGqEofoPQND1J6E0j48B-jWGwNCaEnk4TIk8JiXEpmgggA)1 parent 9a1c1a9 commit 66e595c
File tree
2 files changed
+17
-9
lines changed- sdk/storage/storage-file-datalake
- src/utils
2 files changed
+17
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
Lines changed: 15 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
565 | 565 | | |
566 | 566 | | |
567 | 567 | | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | 568 | | |
573 | 569 | | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
579 | 585 | | |
580 | 586 | | |
581 | 587 | | |
| |||
0 commit comments