Add conversions for from/to Windows Filetime to UNIX Epoch. Decimal.js is used to prevent rounding errors during conversion.
This commit is contained in:
parent
2c0f48f4e5
commit
d27fa43120
@ -2261,6 +2261,20 @@ const OperationConfig = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"From Windows Filetime To UNIX":{
|
||||||
|
description: "Converts a Windows Filetime timestamp to a datetime format",
|
||||||
|
run: DateTime.runFromFiletimeToUnix,
|
||||||
|
inputType: "string",
|
||||||
|
outputType: "string",
|
||||||
|
args: []
|
||||||
|
},
|
||||||
|
"To Windows Filetime From UNIX":{
|
||||||
|
description: "Parses a datetime string in UTC and returns the corresponding Windows Filetime timestamp",
|
||||||
|
run: DateTime.runToFiletimeFromUnix,
|
||||||
|
inputType: "string",
|
||||||
|
outputType: "string",
|
||||||
|
args: []
|
||||||
|
},
|
||||||
"Translate DateTime Format": {
|
"Translate DateTime Format": {
|
||||||
description: "Parses a datetime string in one format and re-writes it in another.<br><br>Run with no input to see the relevant format string examples.",
|
description: "Parses a datetime string in one format and re-writes it in another.<br><br>Run with no input to see the relevant format string examples.",
|
||||||
run: DateTime.runTranslateFormat,
|
run: DateTime.runTranslateFormat,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import Decimal from 'decimal.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date and time operations.
|
* Date and time operations.
|
||||||
*
|
*
|
||||||
@ -78,6 +80,41 @@ const DateTime = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Windows FILETIME to Unix Epoch time.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args (not used)
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
runFromFiletimeToUnix: function(input, args) {
|
||||||
|
input = new Decimal(input);
|
||||||
|
input = input.sub(116444736000000000).div(10000000);
|
||||||
|
if(input.gte(0) && input.lt(Math.pow(2,31))){
|
||||||
|
return input.toString();
|
||||||
|
} else {
|
||||||
|
throw "Date " + input + " is not a valid date";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Unix Epoch time to Windows FILETIME.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args (not used)
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
runToFiletimeFromUnix: function(input, args) {
|
||||||
|
input = new Decimal(input);
|
||||||
|
if(input.gte(0) && input.lt(Math.pow(2,31))){
|
||||||
|
return input.mul(10000000).add(116444736000000000).toHex();
|
||||||
|
} else {
|
||||||
|
throw "Date " + input + " is not a valid date";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
|
Loading…
Reference in New Issue
Block a user