moment tz parse+timestamp

node v14.18.1
version: 1.0.0
endpointsharetweet
const moment = require("moment") const { deepStrictEqual: assert } = require('assert') const formValues = { birth: '1987-07-22' } function getUtcOffset(date, format) { return moment(date, format).utcOffset() } const dateFormat = 'YYYY-MM-DD'; let timeFormat = dateFormat.concat(' HH:MM:SS'); let date = moment(formValues.birth, `${dateFormat} ${timeFormat}`); console.log(`date: [${typeof date}] ${date}`); assert(date instanceof moment, true) assert(date.toString(), 'Wed Jul 22 1987 00:00:00 GMT+0200') let offset = getUtcOffset(formValues.birth, timeFormat); console.log(`offset: [${typeof offset}] ${offset}`); assert(typeof offset, 'number') assert(offset, 120) var status = moment(date, timeFormat).add(offset, 'minutes').format(timeFormat); console.log(`status: [${typeof status}] ${status}`); assert(typeof status, 'string') assert(offset, 120) const returnResult = parseInt(moment(status, timeFormat).format('X')) console.log(`return result: [${typeof returnResult}] ${returnResult}`); assert(typeof returnResult, 'number') assert(returnResult, 553910400) assert(moment.unix(returnResult).toString(), 'Wed Jul 22 1987 00:00:00 GMT+0200')
Loading…

no comments

    sign in to comment