You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Will Heger <wi...@gmail.com> on 2013/03/06 07:12:35 UTC

map timezones

So, let's say that I stamp documents with UTC or epoch values when
recording time values.

Eventually, I will need to do reporting and math on these values using
local time.  Now if there existed a function like...

Date(stamp).localTime("New York")

...that would yield a deterministic result, so it's Kosher for Couch.  The
underlying math would be either UTC-5 or UTC-4 depending on the year and US
law, but the mapped output would be predictable.

That said, I don't think such an animal exists in default JS.  The
getTimezoneOffset() assumes the browser's time which is fraught. Firstly, I
might need "Los Angeles" time and not "New York" time and that can't depend
on where my CouchDB server is installed. Also I need a map that's aware of
EDT vs EST on a historical basis so that a a particular UTC value in 1995
when daylight savings time switchover was at a different hour is captured.

Anyway, I can make sure to convert times inbound which loses other
reporting functionality like timechange sensitive math or I could store
both at the cost of an extra field.

Any pointers?

Thanks,
-Will

Re: map timezones

Posted by Jens Alfke <je...@couchbase.com>.
On Mar 5, 2013, at 10:12 PM, Will Heger <wi...@gmail.com> wrote:

> Eventually, I will need to do reporting and math on these values using
> local time.

What’s “local time”? The time zone of the server? A map/reduce function has to be a “pure” function, so it can’t depend on any external inputs that might change, such as the current timezone.

Time zone conversions should be done by the client (or an app server), not the database. 

(Besides which,  JavaScript date operations are seriously slow, and can hurt performance of your CouchDB.)

—Jens

Re: map timezones

Posted by Ryan Ramage <ry...@gmail.com>.
Yes, date stuff in js can be a pain. That's why lately I turn to moment.js

http://momentjs.com/

It can run browser, node, and in couchdb map, show and list functions using
require. It will alleviate many headaches. It will do many of the fun math
ops.

That being said, I prefer to store millisecond timestamps. Some other like
storing utc strings as they are easier to look at when browsing docs.
Then only do the final conversion to a printable date on display.
On Mar 5, 2013 11:13 PM, "Will Heger" <wi...@gmail.com> wrote:

> So, let's say that I stamp documents with UTC or epoch values when
> recording time values.
>
> Eventually, I will need to do reporting and math on these values using
> local time.  Now if there existed a function like...
>
> Date(stamp).localTime("New York")
>
> ...that would yield a deterministic result, so it's Kosher for Couch.  The
> underlying math would be either UTC-5 or UTC-4 depending on the year and US
> law, but the mapped output would be predictable.
>
> That said, I don't think such an animal exists in default JS.  The
> getTimezoneOffset() assumes the browser's time which is fraught. Firstly, I
> might need "Los Angeles" time and not "New York" time and that can't depend
> on where my CouchDB server is installed. Also I need a map that's aware of
> EDT vs EST on a historical basis so that a a particular UTC value in 1995
> when daylight savings time switchover was at a different hour is captured.
>
> Anyway, I can make sure to convert times inbound which loses other
> reporting functionality like timechange sensitive math or I could store
> both at the cost of an extra field.
>
> Any pointers?
>
> Thanks,
> -Will
>