Skip to content

Commit 7526f4d

Browse files
committed
Generate Epoch Time Operation Added
1 parent 4c3324a commit 7526f4d

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/core/config/Categories.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
"Windows Filetime to UNIX Timestamp",
262262
"UNIX Timestamp to Windows Filetime",
263263
"Extract dates",
264+
"Generate Current Epoch",
264265
"Sleep"
265266
]
266267
},
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @author n1073645 [n1073645@gmail.com]
3+
* @copyright Crown Copyright 2020
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
9+
/**
10+
* GenerateCurrentEpoch operation
11+
*/
12+
class GenerateCurrentEpoch extends Operation {
13+
14+
/**
15+
* GenerateCurrentEpoch constructor
16+
*/
17+
constructor() {
18+
super();
19+
20+
this.name = "Generate Current Epoch";
21+
this.module = "Default";
22+
this.description = "Generates the current time(in seconds/milliseconds) since the UNIX epoch.";
23+
this.infoURL = "https://wikipedia.org/wiki/Unix_time";
24+
this.inputType = "string";
25+
this.outputType = "string";
26+
this.args = [
27+
{
28+
name: "Granularity",
29+
type: "option",
30+
value: ["Milliseconds", "Seconds"]
31+
}
32+
];
33+
}
34+
35+
/**
36+
* @param {string} input
37+
* @param {Object[]} args
38+
* @returns {string}
39+
*/
40+
run(input, args) {
41+
if (args[0] === "Milliseconds")
42+
return (new Date()).getTime().toString();
43+
else
44+
return Math.round((new Date()).getTime() / 1000).toString();
45+
}
46+
47+
}
48+
49+
export default GenerateCurrentEpoch;

0 commit comments

Comments
 (0)