Date/time functions
formatDateTime
Commentary
added in 0.0.17
Generates datetime's for time specified in milliseconds, in the default pattern of yyyy-MM-dd'T'HH:mm:ss.SSSZZ.
Optionally, supply the format with format, which must be a valid JodaTime pattern.
Examples
Default formatting
Omit format for the default formatting.
{
"_gen": "formatDateTime",
"ms": {
"_gen": "now"
}
}
[
"2024-04-25T13:28:47.262-07:00"
]
Specify a format
Set format to control the output string.
{
"_gen": "formatDateTime",
"ms": {
"_gen": "now"
},
"format": "yyyy-MM-dd"
}
[
"2024-04-25"
]
Dates in the past
Because formatDateTime is driven off Unix milliseconds values, you can generate timestamps in the past or future simply by using math.
In this example, timestamps are generated anywhere between 1 and 6 months in the past, whose offsets are represented by 2629746000 and 15778476000 milliseconds respectively.
{
"_gen": "formatDateTime",
"ms": {
"_gen": "math",
"expr": "timestamp - offset",
"names": {
"timestamp": {
"_gen": "now"
},
"offset": {
"_gen": "uniformDistribution",
"bounds": [
2629746000,
15778476000
],
"decimals": 0
}
}
},
"format": "yyyy-MM-dd HH:mm:ss.SSS"
}
[
"2024-03-16 08:16:09.324",
"2023-12-01 13:02:18.413",
"2023-12-12 23:15:34.205",
"2023-11-05 10:05:46.095",
"2024-02-12 22:16:21.182"
]
Set the timezone
By default, all timestamps are printed in UTC, but you can change this by supplying a timezone parameter. The value of timezone must correspond to a JodaTime timezone ID (like Asia/Bahrain) or the value System, which will pick up the default timezone on the system where ShadowTraffic is currently running.
{
"_gen": "formatDateTime",
"ms": {
"_gen": "now"
},
"timezone": "America/Los_Angeles"
}
[
"2024-04-25T13:28:47.262-07:00"
]
Specification
JSON schema
{
"type": "object",
"properties": {
"ms": {
"oneOf": [
{
"type": "number"
},
{
"type": "object",
"properties": {
"_gen": {
"type": "string"
}
},
"required": [
"_gen"
]
}
]
},
"format": {
"type": "string"
},
"timezone": {
"type": "string"
}
},
"required": [
"ms"
]
}