Skip to content

Instantly share code, notes, and snippets.

@kconragan
Created April 18, 2012 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kconragan/2410086 to your computer and use it in GitHub Desktop.
Save kconragan/2410086 to your computer and use it in GitHub Desktop.
for(i = 0; i < results.length; i++) {
var row = results[i];
// construct timestamp for raw results
// YYYY-MM-DD H:H ZZ
// Sample: 2012-04-13 00:10 +0000
var t =row[0] + "-" + row[1] + "-" + row[2] + ' ' + row[3] + ":" + row[4] + ' +0000'
// TODO
// format date an respect timezone
// documentation says this method is slow
// http://momentjs.com/docs/#/parsing/string-format/
//
// also, time appears to be getting rounded even though
// I'm forcing UTC time by appending +0000 to string
// see output of console.log below
var timestamp = moment(t, "YYYY-MM-DD HH ZZ");
// this is faster, but ugly and some values are indexed at 0
var foo = moment([
row[0], // YYYY
row[1] - 1, // MM
row[2], // DD
row[3], // HH
row[4] // H
])
console.log('original', t, 'format', timestamp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment