title: Mongodb time series data and time zone handling
body: <p>I'm creating using node.js and mongodb an application that stores all temperature values by hour in a day.
  Temperature values should be shown in a dashboard according the timezone where the sensor is located. 
  I created a data model following the recommendation for time series data but I don't know how to deal with timezone because mongodb stores dates in UTC so in my data model the object "hours" has static fields for every hour of the day.</p>
  
  <pre><code>// Temperatures by hour in a day.
  {
   dateStart: ISODate("2016-08-06T00:00:00.000Z"), // This is the start of the day
   timeZone: "Europe/Madrid", // We could store the time zone of the sensor.
   hours: {  // I'm not sure how to deal with these values. Should be UTC hours too?
    0: 20
    1: 21,
    2: 24,
    .
    .
    .
    23: 16
   }
  }
  </code></pre>
  
  <p><strong>The question is: how can I deal with timezone?</strong></p>
  
  <p>In my local time the start of a day (2016-08-06T00:00:00) is converted to UTC to 2016-08-05T22:00:00.000+02:00.</p>
  
  <p>A first approach could be:</p>
  
  <ol>
  <li>Sensor time zone is 'Europe/Madrid' (CEST, 02:00 diff from UTC)</li>
  <li>Get the start of day using 'Europe/Madrid time zone, convert it to UTC and store it in database. Field startDate will be "2016-08-05T22:00:00.000Z"</li>
  <li>In order to store a 25 C temperature for an hour: Get local time ('Europe/Madrid'), for example 18h, then convert to UTC. Result is 16h. So hours.16=25.</li>
  </ol>
  
  <p><strong>In this case we have UTC times in star date but the object of hours is not UTC. It is 'Europe/Madrid and I'm not very convinced about this decision.</strong></p>
  
  <p><strong>Any ideas for improving this design?</strong></p>