Tidied up changes to filetime operations and brought tests up to date

This commit is contained in:
n1474335 2017-07-03 15:25:14 +00:00
parent e7cea889ab
commit 183c57643b
3 changed files with 16 additions and 8 deletions

View File

@ -2303,7 +2303,7 @@ const OperationConfig = {
value: DateTime.UNITS value: DateTime.UNITS
}, },
{ {
name: "Input Format", name: "Input format",
type: "option", type: "option",
value: DateTime.FILETIME_FORMATS value: DateTime.FILETIME_FORMATS
} }
@ -2321,7 +2321,7 @@ const OperationConfig = {
value: DateTime.UNITS value: DateTime.UNITS
}, },
{ {
name: "Output Format", name: "Output format",
type: "option", type: "option",
value: DateTime.FILETIME_FORMATS value: DateTime.FILETIME_FORMATS
} }

View File

@ -89,14 +89,17 @@ const DateTime = {
* @returns {string} * @returns {string}
*/ */
runFromFiletimeToUnix: function(input, args) { runFromFiletimeToUnix: function(input, args) {
let units = args[0]; let units = args[0],
let format = args[1]; format = args[1];
if (format === "Hex") { if (format === "Hex") {
input = new BigInteger(input, 16); input = new BigInteger(input, 16);
} else { } else {
input = new BigInteger(input); input = new BigInteger(input);
} }
input = input.subtract(new BigInteger("116444736000000000")); input = input.subtract(new BigInteger("116444736000000000"));
if (units === "Seconds (s)"){ if (units === "Seconds (s)"){
input = input.divide(new BigInteger("10000000")); input = input.divide(new BigInteger("10000000"));
} else if (units === "Milliseconds (ms)") { } else if (units === "Milliseconds (ms)") {
@ -108,6 +111,7 @@ const DateTime = {
} else { } else {
throw "Unrecognised unit"; throw "Unrecognised unit";
} }
return input.toString(); return input.toString();
}, },
@ -121,9 +125,11 @@ const DateTime = {
* @returns {string} * @returns {string}
*/ */
runToFiletimeFromUnix: function(input, args) { runToFiletimeFromUnix: function(input, args) {
let units = args[0]; let units = args[0],
let format = args[1]; format = args[1];
input = new BigInteger(input); input = new BigInteger(input);
if (units === "Seconds (s)"){ if (units === "Seconds (s)"){
input = input.multiply(new BigInteger("10000000")); input = input.multiply(new BigInteger("10000000"));
} else if (units === "Milliseconds (ms)") { } else if (units === "Milliseconds (ms)") {
@ -135,7 +141,9 @@ const DateTime = {
} else { } else {
throw "Unrecognised unit"; throw "Unrecognised unit";
} }
input = input.add(new BigInteger("116444736000000000")); input = input.add(new BigInteger("116444736000000000"));
if (format === "Hex"){ if (format === "Hex"){
return input.toString(16); return input.toString(16);
} else { } else {

View File

@ -16,7 +16,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "Windows Filetime to UNIX Timestamp", op: "Windows Filetime to UNIX Timestamp",
args: ["Nanoseconds (ns)"], args: ["Nanoseconds (ns)", "Decimal"],
}, },
], ],
}, },
@ -27,7 +27,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "UNIX Timestamp to Windows Filetime", op: "UNIX Timestamp to Windows Filetime",
args: ["Nanoseconds (ns)"], args: ["Nanoseconds (ns)", "Decimal"],
}, },
], ],
}, },