From 003e076b008a0bcd62ff3648ab98fe704b8638bd Mon Sep 17 00:00:00 2001 From: Bwhit1 Date: Sat, 10 Jun 2017 23:42:02 -0400 Subject: [PATCH] modifications to FILETIME --- src/core/config/OperationConfig.js | 20 ++++++++++++--- src/core/operations/DateTime.js | 39 ++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 346ca6a7..7472e93f 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -2261,19 +2261,31 @@ const OperationConfig = { } ] }, - "From Windows Filetime To UNIX":{ + "Windows Filetime to UNIX Timestamp":{ description: "Converts a Windows Filetime timestamp to a datetime format", run: DateTime.runFromFiletimeToUnix, inputType: "string", outputType: "string", - args: [] + args: [ + { + name: "Units", + type: "Option", + value: DateTime.UNITS + } + ] }, - "To Windows Filetime From UNIX":{ + "UNIX Timestamp to Windows Filetime":{ description: "Parses a datetime string in UTC and returns the corresponding Windows Filetime timestamp", run: DateTime.runToFiletimeFromUnix, inputType: "string", outputType: "string", - args: [] + args: [ + { + name: "Units", + type: "Option", + value: DateTime.UNITS + } + ] }, "Translate DateTime Format": { description: "Parses a datetime string in one format and re-writes it in another.

Run with no input to see the relevant format string examples.", diff --git a/src/core/operations/DateTime.js b/src/core/operations/DateTime.js index f3c90241..c9d9645d 100755 --- a/src/core/operations/DateTime.js +++ b/src/core/operations/DateTime.js @@ -1,4 +1,6 @@ -import Decimal from "../lib/decimal.min.js"; +//import Decimal from "../lib/decimal.min.js"; +import Utils from "../Utils.js"; +import {BigInteger} from "jsbn"; /** * Date and time operations. @@ -83,35 +85,52 @@ const DateTime = { /** * Converts a Windows FILETIME to Unix Epoch time. * + * @author bwhitn [brian.m.whitney@outlook.com] * @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(); + let units = args[0], offset = new BigInteger("116444736000000000"); + input = new BigInteger(input,16).subtract(offset); + if (units === "Seconds (s)"){ + input = input.divide(new BigInteger("10000000")); + } else if (units === "Milliseconds (ms)") { + input = input.divide(new BigInteger("10000")); + } else if (units === "Microseconds (μs)") { + input = input.divide(new BigInteger("10")); + } else if (units === "Nanoseconds (ns)") { + input = input.multiply(new BigInteger("100")); } else { - throw "Date " + input + " is not a valid date"; + throw "The value " + input + " cannot be expressed as a UNIX timestamp."; } + return input.toString(); }, /** * Converts a Unix Epoch time to Windows FILETIME. * + * @author bwhitn [brian.m.whitney@outlook.com] * @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(); + let units = args[0], offset = new BigInteger("116444736000000000"); + input = new BigInteger(input); + if (units === "Seconds (s)"){ + input = input.multiply(new BigInteger("10000000")).add(offset); + } else if (units === "Milliseconds (ms)") { + input = input.multiply(new BigInteger("10000")).add(offset); + } else if (units === "Microseconds (μs)") { + input = input.multiply(new BigInteger("10")).add(offset); + } else if (units === "Nanoseconds (ns)") { + input = input.divide(new BigInteger("100")).add(offset); } else { - throw "Date " + input + " is not a valid date"; + throw "The value " + input + " cannot be expressed as a UNIX timestamp."; } + return input.toString(); },