Skip to content

Instantly share code, notes, and snippets.

@chrisabrams
Created August 15, 2016 20:46
Show Gist options
  • Save chrisabrams/d57c032581b4462eac74ea4b9413628e to your computer and use it in GitHub Desktop.
Save chrisabrams/d57c032581b4462eac74ea4b9413628e to your computer and use it in GitHub Desktop.
dates and times with rethinkdb
convertDateToDatabaseTime4(d) {
var date = (d) ? moment(d) : moment(),
year = parseInt(date.format('YYYY')),
month = parseInt(date.format('M')),
day = parseInt(date.format('D'))
return r.time(year, month, day, '-04:00')
}
convertDateToDatabaseTime7(year, month, day, hour = 0, minute = 0, second = 0, timezone = '-04:00') {
// Allows for the first argument to be "2016-06-30"
if(arguments.length == 3) {
var date = moment(arguments[0])
year = parseInt(date.format('YYYY'))
month = parseInt(date.format('M'))
day = parseInt(date.format('D'))
hour = parseInt(arguments[1])
minute = parseInt(arguments[2])
}
// Makes second and timezone optional
if(arguments.length == 5) {
year = parseInt(arguments[0])
month = parseInt(arguments[1])
day = parseInt(arguments[2])
hour = parseInt(arguments[3])
minute = parseInt(arguments[4])
}
year = parseInt(year)
month = parseInt(month)
day = parseInt(day)
hour = parseInt(hour)
minute = parseInt(minute)
second = parseFloat(second)
return r.time(year, month, day, hour, minute, second, timezone)
}
convertEpochToDate(e) {
return moment.unix(e).format('YYYY-MM-DD')
}
convertEpochToDatabaseTime4(e) {
var date = this.convertEpochToDate(e)
return this.convertDateToDatabaseTime4(date)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment