Webhook Date Variable {{PARTICLE_PUBLISHED_AT}} – Timezone

Hi,
I would like to use the {{PARTICLE_PUBLISHED_AT}} variable when forwarding a webhook to ThingSpeak to log my sensor data.
Event times matter to me, so it is important that the event times match my local time. I’m currently setting my timezone manually by calling Time.zone(2) (UTC-offset 2, Summertime in Berlin) and then passing a timestamp to the publish function:

String ts = String(Time.local());
String myvar = String(random(1, 6));

Particle.publish("myevent", 
    "{ \"myvar\": \"" + myvar + "\"," +
    "\"timestamp\": \"" + ts + "\" }", 60, PRIVATE);

It would be easier and less data to send around if I could omit the timestamp, as this is available using {{PARTICLE_PUBLISHED_AT}} anyway. Now the questions are:

  • Which timezone are the particle servers using (I guess UTC?)
  • What would you recommend when dealing with dates and time differences (time zones / summer time)?

Exactly!

I've been dealing with that summer time nonsense for ages, till I convinced my company to stick with UTC stamped data and only do the localization on the client side.
And due to expansion and globalization, they realized it was the right move at the right time :wink:

After all, UTC will never have missing or double hours to deal with. If you wish, you can always just send the current time offset, which is only a few byte and not the full timestamp.

2 Likes

Okay thanks!

Didn’t know about all these problems (double hours e.g), will keep that in mind when dealing with global dates from multiple people.

My projects is a personal one so it’s more convenient to have the dates in my local time.

Yup, when jumping forward from normal (winter) time (in your case MEZ/CET) to summer time (MESZ/CEST) you’ll have a gap of one hour between 2:00 and 3:00 and when falling back to normal time, you’ll have each entry between 2:00 and 3:00 twice.