Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

moment-parseformat

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moment-parseformat - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

244

moment.parseFormat.js

@@ -1,59 +0,56 @@

'use strict';
/* istanbul ignore next */
(function (root, factory) {
/* global define */
if (typeof define === 'function' && define.amd) {
define(['moment'], function (moment) {
moment.parseFormat = factory(moment);
return moment.parseFormat;
});
} else if (typeof exports === 'object') {
module.exports = factory(require('moment'));
/* istanbul ignore next */
if (typeof exports === 'object') {
module.exports = factory()
} else {
root.moment.parseFormat = factory(root.moment);
root.moment.parseFormat = factory()
}
})(this, function (/*moment*/) { // jshint ignore:line
var dayNames = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var abbreviatedDayNames = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var shortestDayNames = ['Su','Mo','Tu','We','Th','Fr','Sa'];
var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var abbreviatedMonthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var amDesignator = 'AM';
var pmDesignator = 'PM';
var lowerAMDesignator = 'am';
var lowerPMDesignator = 'pm';
})(this, function () {
var dayNames = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
var abbreviatedDayNames = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
var shortestDayNames = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
var abbreviatedMonthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
var amDesignator = 'AM'
var pmDesignator = 'PM'
var lowerAMDesignator = 'am'
var lowerPMDesignator = 'pm'
var regexDayNames = new RegExp( dayNames.join('|'), 'i' );
var regexAbbreviatedDayNames = new RegExp( abbreviatedDayNames.join('|'), 'i' );
var regexShortestDayNames = new RegExp( '\\b('+shortestDayNames.join('|')+')\\b', 'i' );
var regexMonthNames = new RegExp( monthNames.join('|'), 'i' );
var regexAbbreviatedMonthNames = new RegExp( abbreviatedMonthNames.join('|'), 'i' );
var regexDayNames = new RegExp(dayNames.join('|'), 'i')
var regexAbbreviatedDayNames = new RegExp(abbreviatedDayNames.join('|'), 'i')
var regexShortestDayNames = new RegExp('\\b(' + shortestDayNames.join('|') + ')\\b', 'i')
var regexMonthNames = new RegExp(monthNames.join('|'), 'i')
var regexAbbreviatedMonthNames = new RegExp(abbreviatedMonthNames.join('|'), 'i')
var regexFirstSecondThirdFourth = /(\d+)(st|nd|rd|th)\b/i;
var regexEndian = /(\d{1,4})([\/\.\-])(\d{1,2})[\/\.\-](\d{1,4})/;
var regexFirstSecondThirdFourth = /(\d+)(st|nd|rd|th)\b/i
var regexEndian = /(\d{1,4})([\/\.\-])(\d{1,2})[\/\.\-](\d{1,4})/
var regexTimezone = /((\+|\-)\d\d:\d\d)$/;
var amOrPm = '('+[amDesignator,pmDesignator].join('|')+')';
var lowerAmOrPm = '('+[lowerAMDesignator,lowerPMDesignator].join('|')+')';
var regexLowerAmOrPm = new RegExp(lowerAmOrPm);
var regexUpperAmOrPm = new RegExp(amOrPm);
var regexHoursWithLeadingZeroDigitMinutesSecondsAmPm = new RegExp( '0\\d\\:\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i' );
var regexHoursWithLeadingZeroDigitMinutesAmPm = new RegExp( '0\\d\\:\\d{1,2}(\\s*)' + amOrPm, 'i' );
var regexHoursWithLeadingZeroDigitAmPm = new RegExp( '0\\d(\\s*)' + amOrPm, 'i' );
var regexHoursMinutesSecondsAmPm = new RegExp( '\\d{1,2}\\:\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i' );
var regexHoursMinutesAmPm = new RegExp( '\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i' );
var regexHoursAmPm = new RegExp( '\\d{1,2}(\\s*)' + amOrPm, 'i' );
var regexTimezone = /((\+|\-)\d\d:\d\d)$/
var amOrPm = '(' + [amDesignator, pmDesignator].join('|') + ')'
var lowerAmOrPm = '(' + [lowerAMDesignator, lowerPMDesignator].join('|') + ')'
var regexLowerAmOrPm = new RegExp(lowerAmOrPm)
var regexUpperAmOrPm = new RegExp(amOrPm)
var regexHoursWithLeadingZeroDigitMinutesSecondsAmPm = new RegExp('0\\d\\:\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i')
var regexHoursWithLeadingZeroDigitMinutesAmPm = new RegExp('0\\d\\:\\d{1,2}(\\s*)' + amOrPm, 'i')
var regexHoursWithLeadingZeroDigitAmPm = new RegExp('0\\d(\\s*)' + amOrPm, 'i')
var regexHoursMinutesSecondsAmPm = new RegExp('\\d{1,2}\\:\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i')
var regexHoursMinutesAmPm = new RegExp('\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i')
var regexHoursAmPm = new RegExp('\\d{1,2}(\\s*)' + amOrPm, 'i')
var regexISO8601HoursWithLeadingZeroMinutesSecondsMilliseconds = /\d{2}:\d{2}:\d{2}\.\d{3}/;
var regexHoursWithLeadingZeroMinutesSeconds = /0\d:\d{2}:\d{2}/;
var regexHoursWithLeadingZeroMinutes = /0\d:\d{2}/;
var regexHoursMinutesSeconds = /\d{1,2}:\d{2}:\d{2}/;
var regexHoursMinutes = /\d{1,2}:\d{2}/;
var regexYearLong = /\d{4}/;
var regexDayLeadingZero = /0\d/;
var regexDay = /\d{1,2}/;
var regexYearShort = /\d{2}/;
var regexISO8601HoursWithLeadingZeroMinutesSecondsMilliseconds = /\d{2}:\d{2}:\d{2}\.\d{3}/
var regexHoursWithLeadingZeroMinutesSeconds = /0\d:\d{2}:\d{2}/
var regexHoursWithLeadingZeroMinutes = /0\d:\d{2}/
var regexHoursMinutesSeconds = /\d{1,2}:\d{2}:\d{2}/
var regexHoursMinutes = /\d{1,2}:\d{2}/
var regexYearLong = /\d{4}/
var regexDayLeadingZero = /0\d/
var regexDay = /\d{1,2}/
var regexYearShort = /\d{2}/
var regexFillingWords = /\b(at)\b/i;
var regexFillingWords = /\b(at)\b/i
var regexUnixMillisecondTimestamp = /\d{13}/
var regexUnixTimestamp = /\d{10}/
// option defaults

@@ -64,13 +61,18 @@ var defaultOrder = {

'-': 'YMD'
};
}
function parseDateFormat(dateString, options) {
var format = dateString;
function parseDateFormat (dateString, options) {
var format = dateString
// default options
options = options || {};
options.preferredOrder = options.preferredOrder || defaultOrder;
options = options || {}
options.preferredOrder = options.preferredOrder || defaultOrder
// Unix Millisecond Timestamp ☛ x
format = format.replace(regexUnixMillisecondTimestamp, 'x')
// Unix Timestamp ☛ X
format = format.replace(regexUnixTimestamp, 'X')
// escape filling words
format = format.replace(regexFillingWords, '[$1]');
format = format.replace(regexFillingWords, '[$1]')

@@ -80,10 +82,10 @@ // DAYS

// Monday ☛ dddd
format = format.replace( regexDayNames, 'dddd');
format = format.replace(regexDayNames, 'dddd')
// Mon ☛ ddd
format = format.replace( regexAbbreviatedDayNames, 'ddd');
format = format.replace(regexAbbreviatedDayNames, 'ddd')
// Mo ☛ dd
format = format.replace( regexShortestDayNames, 'dd');
format = format.replace(regexShortestDayNames, 'dd')
// 1st, 2nd, 23rd ☛ do
format = format.replace( regexFirstSecondThirdFourth, 'Do');
format = format.replace(regexFirstSecondThirdFourth, 'Do')

@@ -93,8 +95,8 @@ // MONTHS

// January ☛ MMMM
format = format.replace( regexMonthNames, 'MMMM');
format = format.replace(regexMonthNames, 'MMMM')
// Jan ☛ MMM
format = format.replace( regexAbbreviatedMonthNames, 'MMM');
format = format.replace(regexAbbreviatedMonthNames, 'MMM')
// replace endians, like 8/20/2010, 20.8.2010 or 2010-8-20
format = format.replace( regexEndian, replaceEndian.bind(null, options));
format = format.replace(regexEndian, replaceEndian.bind(null, options))

@@ -104,31 +106,31 @@ // TIME

// timezone +02:00 ☛ Z
format = format.replace(regexTimezone, 'Z');
format = format.replace(regexTimezone, 'Z')
// 23:39:43.331 ☛ 'HH:mm:ss.SS'
format = format.replace(regexISO8601HoursWithLeadingZeroMinutesSecondsMilliseconds, 'HH:mm:ss.SSS');
format = format.replace(regexISO8601HoursWithLeadingZeroMinutesSecondsMilliseconds, 'HH:mm:ss.SSS')
// 05:30:20pm ☛ hh:mm:ssa
format = format.replace(regexHoursWithLeadingZeroDigitMinutesSecondsAmPm, 'hh:mm:ss$1');
format = format.replace(regexHoursWithLeadingZeroDigitMinutesSecondsAmPm, 'hh:mm:ss$1')
// 10:30:20pm ☛ h:mm:ssa
format = format.replace(regexHoursMinutesSecondsAmPm, 'h:mm:ss$1');
format = format.replace(regexHoursMinutesSecondsAmPm, 'h:mm:ss$1')
// 05:30pm ☛ hh:mma
format = format.replace(regexHoursWithLeadingZeroDigitMinutesAmPm, 'hh:mm$1');
format = format.replace(regexHoursWithLeadingZeroDigitMinutesAmPm, 'hh:mm$1')
// 10:30pm ☛ h:mma
format = format.replace(regexHoursMinutesAmPm, 'h:mm$1');
format = format.replace(regexHoursMinutesAmPm, 'h:mm$1')
// 05pm ☛ hha
format = format.replace(regexHoursWithLeadingZeroDigitAmPm, 'hh$1');
format = format.replace(regexHoursWithLeadingZeroDigitAmPm, 'hh$1')
// 10pm ☛ ha
format = format.replace(regexHoursAmPm, 'h$1');
format = format.replace(regexHoursAmPm, 'h$1')
// 05:30:20 ☛ HH:mm:ss
format = format.replace(regexHoursWithLeadingZeroMinutesSeconds, 'HH:mm:ss');
format = format.replace(regexHoursWithLeadingZeroMinutesSeconds, 'HH:mm:ss')
// 10:30:20 ☛ H:mm:ss
format = format.replace(regexHoursMinutesSeconds, 'H:mm:ss');
format = format.replace(regexHoursMinutesSeconds, 'H:mm:ss')
// 05:30 ☛ H:mm
format = format.replace(regexHoursWithLeadingZeroMinutes, 'HH:mm');
format = format.replace(regexHoursWithLeadingZeroMinutes, 'HH:mm')
// 10:30 ☛ HH:mm
format = format.replace(regexHoursMinutes, 'H:mm');
format = format.replace(regexHoursMinutes, 'H:mm')
// Check if AM and determine the case of 'a' we need
if(regexUpperAmOrPm.test(dateString)) {
format += 'A';
} else if(regexLowerAmOrPm.test(dateString)) {
format += 'a';
if (regexUpperAmOrPm.test(dateString)) {
format += 'A'
} else if (regexLowerAmOrPm.test(dateString)) {
format += 'a'
}

@@ -139,12 +141,12 @@

// Lets check for 4 digits first, these are years for sure
format = format.replace(regexYearLong, 'YYYY');
format = format.replace(regexYearLong, 'YYYY')
// now, the next number, if existing, must be a day
format = format.replace(regexDayLeadingZero, 'DD');
format = format.replace(regexDay, 'D');
format = format.replace(regexDayLeadingZero, 'DD')
format = format.replace(regexDay, 'D')
// last but not least, there could still be a year left
format = format.replace(regexYearShort, 'YY');
format = format.replace(regexYearShort, 'YY')
return format;
return format
}

@@ -155,21 +157,20 @@

// we try to make a smart decision to identify the order
function replaceEndian(options, matchedPart, first, separator, second, third) {
var parts;
var hasSingleDigit = Math.min(first.length, second.length, third.length) === 1;
var hasQuadDigit = Math.max(first.length, second.length, third.length) === 4;
var index = -1;
var preferredOrder = typeof options.preferredOrder === 'string' ? options.preferredOrder : options.preferredOrder[separator];
function replaceEndian (options, matchedPart, first, separator, second, third) {
var parts
var hasSingleDigit = Math.min(first.length, second.length, third.length) === 1
var hasQuadDigit = Math.max(first.length, second.length, third.length) === 4
var preferredOrder = typeof options.preferredOrder === 'string' ? options.preferredOrder : options.preferredOrder[separator]
first = parseInt(first, 10);
second = parseInt(second, 10);
third = parseInt(third, 10);
parts = [first, second, third];
preferredOrder = preferredOrder.toUpperCase();
first = parseInt(first, 10)
second = parseInt(second, 10)
third = parseInt(third, 10)
parts = [first, second, third]
preferredOrder = preferredOrder.toUpperCase()
// If first is a year, order will always be Year-Month-Day
if (first > 31) {
parts[0] = hasQuadDigit ? 'YYYY' : 'YY';
parts[1] = hasSingleDigit ? 'M' : 'MM';
parts[2] = hasSingleDigit ? 'D' : 'DD';
return parts.join(separator);
parts[0] = hasQuadDigit ? 'YYYY' : 'YY'
parts[1] = hasSingleDigit ? 'M' : 'MM'
parts[2] = hasSingleDigit ? 'D' : 'DD'
return parts.join(separator)
}

@@ -180,6 +181,6 @@

if (second > 12) {
parts[0] = hasSingleDigit ? 'M' : 'MM';
parts[1] = hasSingleDigit ? 'D' : 'DD';
parts[2] = hasQuadDigit ? 'YYYY' : 'YY';
return parts.join(separator);
parts[0] = hasSingleDigit ? 'M' : 'MM'
parts[1] = hasSingleDigit ? 'D' : 'DD'
parts[2] = hasQuadDigit ? 'YYYY' : 'YY'
return parts.join(separator)
}

@@ -189,36 +190,25 @@

if (third > 31) {
parts[2] = hasQuadDigit ? 'YYYY' : 'YY';
parts[2] = hasQuadDigit ? 'YYYY' : 'YY'
// ... try to find day in first and second.
// If found, the remaining part is the month.
switch (true) {
case first > 12:
parts[0] = hasSingleDigit ? 'D' : 'DD';
parts[1] = hasSingleDigit ? 'M' : 'MM';
return parts.join(separator);
case second > 12:
parts[0] = hasSingleDigit ? 'M' : 'MM';
parts[1] = hasSingleDigit ? 'D' : 'DD';
return parts.join(separator);
default: // sorry
if (preferredOrder[0] === 'M') {
parts[0] = hasSingleDigit ? 'M' : 'MM';
parts[1] = hasSingleDigit ? 'D' : 'DD';
return parts.join(separator);
}
parts[0] = hasSingleDigit ? 'D' : 'DD';
parts[1] = hasSingleDigit ? 'M' : 'MM';
return parts.join(separator);
if (preferredOrder[0] === 'M') {
parts[0] = hasSingleDigit ? 'M' : 'MM'
parts[1] = hasSingleDigit ? 'D' : 'DD'
return parts.join(separator)
}
parts[0] = hasSingleDigit ? 'D' : 'DD'
parts[1] = hasSingleDigit ? 'M' : 'MM'
return parts.join(separator)
}
// if we had no luck until here, we use the preferred order
parts[preferredOrder.indexOf('D')] = hasSingleDigit ? 'D' : 'DD';
parts[preferredOrder.indexOf('M')] = hasSingleDigit ? 'M' : 'MM';
parts[preferredOrder.indexOf('Y')] = hasQuadDigit ? 'YYYY' : 'YY';
parts[preferredOrder.indexOf('D')] = hasSingleDigit ? 'D' : 'DD'
parts[preferredOrder.indexOf('M')] = hasSingleDigit ? 'M' : 'MM'
parts[preferredOrder.indexOf('Y')] = hasQuadDigit ? 'YYYY' : 'YY'
return parts.join(separator);
return parts.join(separator)
}
return parseDateFormat;
});
return parseDateFormat
})
{
"name": "moment-parseformat",
"version": "1.0.1",
"description": "A moment.js plugin to extract the format of a date/time string",
"main": "moment.parseFormat.js",
"scripts": {
"test": "grunt test",
"prepublish": "semantic-release pre",
"postpublish": "semantic-release post"
"test": "standard && npm run test:node | tap-spec",
"test:node": "node tests/moment-parseformat-test.js",
"coverage": "istanbul cover tests/moment-parseformat-test.js && istanbul-coveralls ",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
"type": "git",
"url": "git://github.com/gr2m/moment.parseFormat.git"
"url": "https://github.com/gr2m/moment-parseformat.git"
},

@@ -23,15 +23,19 @@ "keywords": [

"bugs": {
"url": "https://github.com/gr2m/moment.parseFormat/issues"
"url": "https://github.com/gr2m/moment-parseformat/issues"
},
"homepage": "http://gr2m.github.io/moment.parseFormat",
"dependencies": {
"moment": "^2.10.3"
"dependencies": {},
"devDependencies": {
"bootstrap-editable-table": "https://github.com/gr2m/bootstrap-editable-table#gh-pages",
"istanbul": "^0.3.5",
"istanbul-coveralls": "^1.0.1",
"semantic-release": "^4.3.4",
"standard": "^3.11.1",
"tap-spec": "^3.0.0",
"tape": "^4.2.0"
},
"devDependencies": {
"grunt": "~0.4.2",
"grunt-bump": "0.0.13",
"grunt-contrib-qunit": "~0.4.0",
"grunt-contrib-watch": "~0.5.3",
"semantic-release": "^3.3.1"
}
}
"release": {
"branch": "gh-pages"
},
"version": "1.1.0"
}

@@ -1,50 +0,59 @@

/* global moment, test, equal */
'use strict'
test('standard cases', function() {
'use strict';
var test = require('tape')
var moment = require('moment')
equal( moment.parseFormat('Thursday 9:20pm'), 'dddd h:mma', 'Thursday 9:20pm → dddd h:mma' );
equal( moment.parseFormat('Thursday, February 6th, 2014 9:20pm'), 'dddd, MMMM Do, YYYY h:mma', 'Thursday, February 6th, 2014 9:20pm → dddd, MMMM Do, YYYY h:mma' );
equal( moment.parseFormat('23:20'), 'H:mm', '23:20 → H:mm' );
equal( moment.parseFormat('02/03/14'), 'MM/DD/YY', '02/03/14 → MM/DD/YY' );
equal( moment.parseFormat('2014-01-10 20:00:15'), 'YYYY-MM-DD H:mm:ss', '2014-01-10 20:00:15 → YYYY-MM-DD H:mm:ss' );
equal( moment.parseFormat('Thursday at 9:20pm'), 'dddd [at] h:mma', 'Thursday at 9:20pm → dddd [at] h:mma' );
});
moment.parseFormat = require('../moment.parseFormat')
test('GitHub issues', function() {
'use strict';
test('standard cases', function (t) {
t.equal(moment.parseFormat('Thursday 9:20pm'), 'dddd h:mma', 'Thursday 9:20pm → dddd h:mma')
t.equal(moment.parseFormat('Thursday, February 6th, 2014 9:20pm'), 'dddd, MMMM Do, YYYY h:mma', 'Thursday, February 6th, 2014 9:20pm → dddd, MMMM Do, YYYY h:mma')
t.equal(moment.parseFormat('23:20'), 'H:mm', '23:20 → H:mm')
t.equal(moment.parseFormat('02/03/14'), 'MM/DD/YY', '02/03/14 → MM/DD/YY')
t.equal(moment.parseFormat('2014-01-10 20:00:15'), 'YYYY-MM-DD H:mm:ss', '2014-01-10 20:00:15 → YYYY-MM-DD H:mm:ss')
t.equal(moment.parseFormat('Thursday at 9:20pm'), 'dddd [at] h:mma', 'Thursday at 9:20pm → dddd [at] h:mma')
t.end()
})
test('GitHub issues', function (t) {
// https://github.com/gr2m/moment.parseFormat/issues/3
equal( moment.parseFormat('Thursday, February 6th, 2014 9:20pm'), 'dddd, MMMM Do, YYYY h:mma', '#3 Thursday, February 6th, 2014 9:20pm -> dddd, MMMM Do, YYYY h:mma' );
equal( moment('Thursday, February 6th, 2014 9:20pm', 'dddd, MMMM Do, YYYY h:mma').date(), 6, '#3 sanity check: "Thursday, February 6th, 2014 9:20pm" parses 6th correctly' );
t.equal(moment.parseFormat('Thursday, February 6th, 2014 9:20pm'), 'dddd, MMMM Do, YYYY h:mma', '#3 Thursday, February 6th, 2014 9:20pm -> dddd, MMMM Do, YYYY h:mma')
t.equal(moment('Thursday, February 6th, 2014 9:20pm', 'dddd, MMMM Do, YYYY h:mma').date(), 6, '#3 sanity check: "Thursday, February 6th, 2014 9:20pm" parses 6th correctly')
// https://github.com/gr2m/moment.parseFormat/issues/4
equal( moment.parseFormat('1.1.2010'), 'D.M.YYYY', '#4 1.1.2010 → D.M.YYYY' );
t.equal(moment.parseFormat('1.1.2010'), 'D.M.YYYY', '#4 1.1.2010 → D.M.YYYY')
// https://github.com/gr2m/moment.parseFormat/issues/11
equal( moment.parseFormat('9-17-1980'), 'M-D-YYYY', '#11 9-17-1980 → M-D-YYYY' );
t.equal(moment.parseFormat('9-17-1980'), 'M-D-YYYY', '#11 9-17-1980 → M-D-YYYY')
// https://github.com/gr2m/moment.parseFormat/issues/11
equal( moment.parseFormat('2014-09-04T01:20:28+02:00'), 'YYYY-MM-DDTHH:mm:ssZ', '#5 2014-02-02T10:11:58+00:00 → YYYY-MM-DDTHH:mm:ssZ' );
t.equal(moment.parseFormat('2014-09-04T01:20:28+02:00'), 'YYYY-MM-DDTHH:mm:ssZ', '#5 2014-02-02T10:11:58+00:00 → YYYY-MM-DDTHH:mm:ssZ')
// https://github.com/gr2m/moment.parseFormat/issues/14
equal( moment.parseFormat('August 26, 2014 02:30pm'), 'MMMM D, YYYY hh:mma', '#5 August 26, 2014 02:30pm → MMMM D, YYYY hh:mma' );
equal( moment.parseFormat('August 06, 2014'), 'MMMM DD, YYYY', '#5 August 06, 2014 → MMMM DD, YYYY' );
t.equal(moment.parseFormat('August 26, 2014 02:30pm'), 'MMMM D, YYYY hh:mma', '#5 August 26, 2014 02:30pm → MMMM D, YYYY hh:mma')
t.equal(moment.parseFormat('August 06, 2014'), 'MMMM DD, YYYY', '#5 August 06, 2014 → MMMM DD, YYYY')
// https://github.com/gr2m/moment.parseFormat/issues/12
equal( moment.parseFormat('3-1-81'), 'D-M-YY', '#12 3-1-81 → D-M-YY' );
t.equal(moment.parseFormat('3-1-81'), 'D-M-YY', '#12 3-1-81 → D-M-YY')
// https://github.com/gr2m/moment.parseFormat/issues/15
equal( moment.parseFormat('01-01-2015'), 'DD-MM-YYYY', '#15 01-01-2015 → DD-MM-YYYY' );
equal( moment.parseFormat('01-01-2015', {preferredOrder: 'MDY'}), 'MM-DD-YYYY', '#15 01-01-2015 (preferredOrder: MDY) → MM-DD-YYYY' );
t.equal(moment.parseFormat('01-01-2015'), 'DD-MM-YYYY', '#15 01-01-2015 → DD-MM-YYYY')
t.equal(moment.parseFormat('01-01-2015', {preferredOrder: 'MDY'}), 'MM-DD-YYYY', '#15 01-01-2015 (preferredOrder: MDY) → MM-DD-YYYY')
// https://github.com/gr2m/moment.parseFormat/pull/21
equal( moment.parseFormat('10/8/2014 5:08:35 PM'), 'M/D/YYYY h:mm:ss A', '#20 10/8/2014 5:08:35 PM → M/D/YYYY h:mm:ss A' );
equal( moment.parseFormat('10/8/2014 5:08:35am'), 'M/D/YYYY h:mm:ssa', '#20 10/8/2014 5:08:35 am → M/D/YYYY h:mm:ssa' );
t.equal(moment.parseFormat('10/8/2014 5:08:35 PM'), 'M/D/YYYY h:mm:ss A', '#20 10/8/2014 5:08:35 PM → M/D/YYYY h:mm:ss A')
t.equal(moment.parseFormat('10/8/2014 5:08:35am'), 'M/D/YYYY h:mm:ssa', '#20 10/8/2014 5:08:35 am → M/D/YYYY h:mm:ssa')
// https://github.com/gr2m/moment.parseFormat/issues/23
equal( moment.parseFormat('2014-23-04T01:20:28.888+02:00'), 'YYYY-MM-DDTHH:mm:ss.SSSZ', '#23 2014-23-04T01:20:28.888+02:00 → YYYY-MM-DDTHH:mm:ss.SSSZ' );
equal( moment.parseFormat('2014-09-04T01:20:28.888+02:00'), 'YYYY-MM-DDTHH:mm:ss.SSSZ', '#23 2014-09-04T01:20:28.888+02:00 → YYYY-MM-DDTHH:mm:ss.SSSZ' );
equal( moment.parseFormat('2014-09-04T01:20:28.888-02:00'), 'YYYY-MM-DDTHH:mm:ss.SSSZ', '#23 2014-09-04T01:20:28.888-02:00 → YYYY-MM-DDTHH:mm:ss.SSSZ' );
equal( moment.parseFormat('2014-09-04T01:20:28.888Z'), 'YYYY-MM-DDTHH:mm:ss.SSSZ', '#23 2014-02-02T10:11:58.888Z → YYYY-MM-DDTHH:mm:ss.SSSZ' );
});
t.equal(moment.parseFormat('2014-23-04T01:20:28.888+02:00'), 'YYYY-MM-DDTHH:mm:ss.SSSZ', '#23 2014-23-04T01:20:28.888+02:00 → YYYY-MM-DDTHH:mm:ss.SSSZ')
t.equal(moment.parseFormat('2014-09-04T01:20:28.888+02:00'), 'YYYY-MM-DDTHH:mm:ss.SSSZ', '#23 2014-09-04T01:20:28.888+02:00 → YYYY-MM-DDTHH:mm:ss.SSSZ')
t.equal(moment.parseFormat('2014-09-04T01:20:28.888-02:00'), 'YYYY-MM-DDTHH:mm:ss.SSSZ', '#23 2014-09-04T01:20:28.888-02:00 → YYYY-MM-DDTHH:mm:ss.SSSZ')
t.equal(moment.parseFormat('2014-09-04T01:20:28.888Z'), 'YYYY-MM-DDTHH:mm:ss.SSSZ', '#23 2014-02-02T10:11:58.888Z → YYYY-MM-DDTHH:mm:ss.SSSZ')
// https://github.com/gr2m/moment.parseFormat/pull/29
t.equal(moment.parseFormat('1434575583'), 'X', '1434575583 → X')
t.equal(moment.parseFormat('1318781876406'), 'x', '1318781876406 → x')
t.end()
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc