Baard
Baard

Reputation: 375

Converting epoch to datetime

I have the following entity:

{
  "q": 524480,
  "t": "~f1520825387781.23",
  "v": "~f8058.0147682"
}

How do i convert the "t" value to a datetime. The value is seconds since epoch.

Upvotes: 1

Views: 42

Answers (1)

Baard
Baard

Reputation: 375

You can use the datetime function, but first you must convert the epoch to an integer representing nanoseconds since epoch.

{
  "_id": "my-pipe",
  "type": "pipe",
  "source": {
    "type": "embedded",
    "entities": [{
      "_id": "foo",
      "q": 524480,
      "t": "~f1520825387781.23",
      "v": "~f8058.0147682"
    }]
  },
  "transform": {
    "type": "dtl",
    "rules": {
      "default": [
        ["add", "timestamp",
          ["datetime",
            ["integer",
              ["*", 1e6, "_S.t"]
            ]
          ]
        ]
      ]
    }
  }
}

This gives you:

[
  {
    "_id": "foo",
    "timestamp": "~t2018-03-12T03:29:47.78123Z"
  }
]

Upvotes: 2

Related Questions