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

moment-parseformat

Package Overview
Dependencies
Maintainers
1
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 0.0.13 to 0.1.0

.travis.yml

54

moment.parseFormat.js

@@ -23,2 +23,4 @@ 'use strict';

var pmDesignator = 'PM';
var lowerAMDesignator = 'am';
var lowerPMDesignator = 'pm';

@@ -34,4 +36,7 @@ var regexDayNames = new RegExp( dayNames.join('|'), 'i' );

var regexTimezone = /\+\d\d:\d\d$/
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' );

@@ -44,2 +49,3 @@ var regexHoursWithLeadingZeroDigitMinutesAmPm = new RegExp( '0\\d\\:\\d{1,2}(\\s*)' + amOrPm, 'i' );

var regexISO8601HoursWithLeadingZeroMinutesSecondsMilliseconds = /\d{2}:\d{2}:\d{2}\.\d{3}/;
var regexHoursWithLeadingZeroMinutesSeconds = /0\d:\d{2}:\d{2}/;

@@ -99,15 +105,16 @@ var regexHoursWithLeadingZeroMinutes = /0\d:\d{2}/;

format = format.replace(regexTimezone, 'Z');
// 23:39:43.331 ☛ 'HH:mm:ss.SS'
format = format.replace(regexISO8601HoursWithLeadingZeroMinutesSecondsMilliseconds, 'HH:mm:ss.SSS');
// 05:30:20pm ☛ hh:mm:ssa
format = format.replace(regexHoursWithLeadingZeroDigitMinutesSecondsAmPm, 'hh:mm:ss$1a');
format = format.replace(regexHoursWithLeadingZeroDigitMinutesSecondsAmPm, 'hh:mm:ss$1');
// 10:30:20pm ☛ h:mm:ssa
format = format.replace(regexHoursMinutesSecondsAmPm, 'h:mm:ss$1a');
format = format.replace(regexHoursMinutesSecondsAmPm, 'h:mm:ss$1');
// 05:30pm ☛ hh:mma
format = format.replace(regexHoursWithLeadingZeroDigitMinutesAmPm, 'hh:mm$1a');
format = format.replace(regexHoursWithLeadingZeroDigitMinutesAmPm, 'hh:mm$1');
// 10:30pm ☛ h:mma
format = format.replace(regexHoursMinutesAmPm, 'h:mm$1a');
format = format.replace(regexHoursMinutesAmPm, 'h:mm$1');
// 05pm ☛ hha
format = format.replace(regexHoursWithLeadingZeroDigitAmPm, 'hh$1a');
format = format.replace(regexHoursWithLeadingZeroDigitAmPm, 'hh$1');
// 10pm ☛ ha
format = format.replace(regexHoursAmPm, 'h$1a');
format = format.replace(regexHoursAmPm, 'h$1');
// 05:30:20 ☛ HH:mm:ss

@@ -122,2 +129,9 @@ format = format.replace(regexHoursWithLeadingZeroMinutesSeconds, 'HH:mm:ss');

// Check if AM and determine the case of 'a' we need
if(regexUpperAmOrPm.test(dateString)) {
format += 'A';
} else if(regexLowerAmOrPm.test(dateString)) {
format += 'a';
}
// do we still have numbers left?

@@ -177,8 +191,20 @@

// If found, the remaining part is the month.
index = first > 12 ? 0 : second > 12 ? 1 : -1;
if (index !== -1) {
parts[index] = hasSingleDigit ? 'D' : 'DD';
index = index === 0 ? 1 : 0;
parts[index] = hasSingleDigit ? 'M' : 'MM';
return parts.join(separator);
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);
}

@@ -185,0 +211,0 @@ }

{
"name": "moment-parseformat",
"version": "0.0.13",
"version": "0.1.0",
"description": "A moment.js plugin to extract the format of a date/time string",
"main": "moment.parseFormat.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "grunt test",
"prepublish": "semantic-release pre",
"postpublish": "semantic-release post"
},

@@ -29,6 +31,7 @@ "repository": {

"grunt": "~0.4.2",
"grunt-bump": "0.0.13",
"grunt-contrib-qunit": "~0.4.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-bump": "0.0.13"
"semantic-release": "^3.3.1"
}
}

@@ -6,5 +6,17 @@ moment.parseFormat – a moment.js plugin

[![Build Status][travis-image]][travis-url]
[travis-url]: https://travis-ci.org/gr2m/moment.parseFormat
[travis-image]: https://api.travis-ci.org/gr2m/moment.parseFormat.png?branch=gh-pages
Installation
------------
Load via script tag
```html
<script src="moment.js"></script>
<script src="moment.parseFormat.js"></script>
```
Install using [bower](http://bower.io/) for usage in browser:

@@ -95,4 +107,4 @@

The moment.parseFormat Plugin have been authored by [Gregor Martynus](https://github.com/gr2m),
proud member of [Team Hoodie](http://hood.ie/). Support our work: [gittip us](https://www.gittip.com/hoodiehq/).
proud member of the [Hoodie Community](http://hood.ie/).
License: MIT

@@ -33,2 +33,19 @@ /* global moment, test, equal */

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' );
// 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' );
// 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' );
// 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' );
});

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