Skip to content

Beyond 3DP seconds causes incorrect format output #96

@TotallyInformation

Description

@TotallyInformation

The following code:

var moment = require('moment')
var parseFormat = require('moment-parseformat')

var dp6 = "2019-05-25T15:30:42.526058+00:00"
var dp5 = "2019-05-25T15:30:42.52605+00:00"

var long6dp = moment(dp6)
var long5dp = moment(dp5)

var fmt6dp = parseFormat(dp6,{preferredOrder: {'/': 'DMY', '.': 'DMY', '-': 'YMD'}})
var fmt5dp = parseFormat(dp5,{preferredOrder: {'/': 'DMY', '.': 'DMY', '-': 'YMD'}})

var fmt6dpMoment = moment(dp6, fmt6dp)
var fmt5dpMoment = moment(dp5, fmt5dp)

console.log( 'long6dp', long6dp.format() )
console.log( 'long5dp', long5dp.format() )
console.log( 'fmt6dp parseFormat', fmt6dp )
console.log( 'fmt5dp parseFormat', fmt5dp )
console.log( 'fmt6dpMoment', fmt6dpMoment.format() )
console.log( 'fmt5dpMoment', fmt5dpMoment.format() )

Produces the following output:

long6dp 2019-05-25T16:30:42+01:00
long5dp 2019-05-25T16:30:42+01:00
fmt6dp parseFormat YYYY-MM-DDTHH:mm:ss.SSSDDDZ
fmt5dp parseFormat YYYY-MM-DDTHH:mm:ss.SSSDDZ
fmt6dpMoment 2019-02-27T15:30:42+00:00
fmt5dpMoment 2019-05-05T16:30:42+01:00

As you can see, anything beyond 3DP on the seconds value results in "D" specifications on the end of the fractional seconds which is clearly incorrect and produces uncertain output from moment.

Reported to me in the following issue:

TotallyInformation/node-red-contrib-moment#24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions