mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
'To UNIX Timestamp' operation now defaults to UTC instead of your local timezone.
This commit is contained in:
parent
c43b67ea90
commit
07fba53b73
2 changed files with 14 additions and 2 deletions
|
@ -2223,7 +2223,7 @@ const OperationConfig = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"To UNIX Timestamp": {
|
"To UNIX Timestamp": {
|
||||||
description: "Parses a datetime string and returns the corresponding UNIX timestamp.<br><br>e.g. <code>Mon 1 January 2001 11:00:00 UTC</code> becomes <code>978346800</code>",
|
description: "Parses a datetime string in UTC and returns the corresponding UNIX timestamp.<br><br>e.g. <code>Mon 1 January 2001 11:00:00</code> becomes <code>978346800</code>",
|
||||||
run: DateTime.runToUnixTimestamp,
|
run: DateTime.runToUnixTimestamp,
|
||||||
inputType: "string",
|
inputType: "string",
|
||||||
outputType: "number",
|
outputType: "number",
|
||||||
|
@ -2232,6 +2232,11 @@ const OperationConfig = {
|
||||||
name: "Units",
|
name: "Units",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: DateTime.UNITS
|
value: DateTime.UNITS
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Treat as UTC",
|
||||||
|
type: "boolean",
|
||||||
|
value: DateTime.TREAT_AS_UTC
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -46,6 +46,12 @@ const DateTime = {
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
TREAT_AS_UTC: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To UNIX Timestamp operation.
|
* To UNIX Timestamp operation.
|
||||||
*
|
*
|
||||||
|
@ -55,7 +61,8 @@ const DateTime = {
|
||||||
*/
|
*/
|
||||||
runToUnixTimestamp: function(input, args) {
|
runToUnixTimestamp: function(input, args) {
|
||||||
let units = args[0],
|
let units = args[0],
|
||||||
d = moment(input);
|
treatAsUTC = args[1],
|
||||||
|
d = treatAsUTC ? moment.utc(input) : moment(input);
|
||||||
|
|
||||||
if (units === "Seconds (s)") {
|
if (units === "Seconds (s)") {
|
||||||
return d.unix();
|
return d.unix();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue