Comparing version 0.2.0 to 0.2.1
@@ -7,10 +7,8 @@ if ( typeof module !== 'undefined' ) { | ||
if ( !(date instanceof Date) ) { | ||
try { | ||
if ( typeof date === 'string' ) { | ||
date = new Date(Date.parse(date)); | ||
} else { | ||
date = new Date(date) | ||
} | ||
} catch(e) { | ||
throw Error(e); | ||
if ( typeof date === 'string' ) { | ||
var parsed = Date.parse(date); | ||
if ( isNaN(parsed) ) { throw Error('Cannot parse \'' + date + '\''); } | ||
date = new Date(parsed); | ||
} else { | ||
date = new Date(date) | ||
} | ||
@@ -17,0 +15,0 @@ } |
{ | ||
"name": "daylight", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "lightweight javascript date formatting", | ||
@@ -18,4 +18,4 @@ "main": "daylight.js", | ||
"opera/11.0..latest", | ||
"iphone/latest", | ||
"ipad/latest", | ||
"iphone/6", | ||
"ipad/6", | ||
"android-browser/latest" | ||
@@ -22,0 +22,0 @@ ] |
# daylight | ||
[![testling](https://ci.testling.com/malantonio/daylight.png)](https://ci.testling.com/malantonio/daylight) | ||
I absolutely love the [moment.js](http://momentjs.com) library, but at times it runs a bit heavier than I really need. I like the simplicity of PHP's built-in `date()` function and wrote this to be sort of similar. | ||
@@ -4,0 +6,0 @@ |
58
test.js
var test = require('tape'); | ||
var formatDate = require('./daylight'); | ||
var date = '2014-05-28 09:00:00'; | ||
var date = '2014/05/28 09:00:00'; | ||
@@ -10,8 +10,8 @@ test('formatDate works', function(t) { | ||
test('date format: YYYY-MM-DD HH:MM:SS', function(t) { | ||
t.equal(formatDate('Y-m-d H:i:s', '2014-05-28 23:00:00'), '2014-05-28 23:00:00'); | ||
test('date format: YYYY/MM/DD HH:MM:SS', function(t) { | ||
t.equal(formatDate('Y/m/d H:i:s', '2014/05/28 23:00:00'), '2014/05/28 23:00:00'); | ||
t.end(); | ||
}); | ||
test('date format: YYYY-MM-DDTHH:MM:SS (UTC timezone)', function(t) { | ||
test('date format: YYYY/MM/DDTHH:MM:SS (UTC timezone)', function(t) { | ||
t.equal(formatDate('Y-m-d\\TH:i:s', '2014-05-28T23:00:00'), '2014-05-28T19:00:00'); | ||
@@ -30,3 +30,3 @@ t.end(); | ||
t.equal(formatDate('d', date), '28'); | ||
t.equal(formatDate('d', '2014-05-01 00:00:00'), '01'); | ||
t.equal(formatDate('d', '2014/05/01 00:00:00'), '01'); | ||
@@ -56,4 +56,4 @@ t.end(); | ||
t.equal(formatDate('N', date), '4'); | ||
t.equal(formatDate('N', '2014-05-24 00:00:00'), '7'); | ||
t.equal(formatDate('N', '2014-05-25 00:00:00'), '1'); | ||
t.equal(formatDate('N', '2014/05/24 00:00:00'), '7'); | ||
t.equal(formatDate('N', '2014/05/25 00:00:00'), '1'); | ||
@@ -66,9 +66,9 @@ t.end(); | ||
t.equal(formatDate('jS', 'May 1 2014'), '1st'); | ||
t.equal(formatDate('jS', '05-02-2014'), '2nd'); | ||
t.equal(formatDate('jS', '2014-05-03 00:00:00'), '3rd'); | ||
t.equal(formatDate('jS', '2014-05-04 00:00:00'), '4th'); | ||
t.equal(formatDate('jS', '2014-05-10 00:00:00'), '10th'); | ||
t.equal(formatDate('jS', '2014-05-11 00:00:00'), '11th'); | ||
t.equal(formatDate('jS', '2014-05-12 00:00:00'), '12th'); | ||
t.equal(formatDate('jS', '2014-05-13 00:00:00'), '13th'); | ||
t.equal(formatDate('jS', '05/02/2014'), '2nd'); | ||
t.equal(formatDate('jS', '2014/05/03 00:00:00'), '3rd'); | ||
t.equal(formatDate('jS', '2014/05/04 00:00:00'), '4th'); | ||
t.equal(formatDate('jS', '2014/05/10 00:00:00'), '10th'); | ||
t.equal(formatDate('jS', '2014/05/11 00:00:00'), '11th'); | ||
t.equal(formatDate('jS', '2014/05/12 00:00:00'), '12th'); | ||
t.equal(formatDate('jS', '2014/05/13 00:00:00'), '13th'); | ||
@@ -80,4 +80,4 @@ t.end(); | ||
t.equal(formatDate('w', date), '3'); | ||
t.equal(formatDate('w', '2014-05-24 00:00:00'), '6'); | ||
t.equal(formatDate('w', '2014-05-25 00:00:00'), '0'); | ||
t.equal(formatDate('w', '2014/05/24 00:00:00'), '6'); | ||
t.equal(formatDate('w', '2014/05/25 00:00:00'), '0'); | ||
@@ -88,4 +88,4 @@ t.end(); | ||
test('numeric day of the year: z', function(t) { | ||
t.equal(formatDate('z', '2014-01-01 00:00:00'), '1'); | ||
t.equal(formatDate('z', '2014-02-03 00:00:00'), '34'); | ||
t.equal(formatDate('z', '2014/01/01 00:00:00'), '1'); | ||
t.equal(formatDate('z', '2014/02/03 00:00:00'), '34'); | ||
@@ -109,3 +109,3 @@ t.end(); | ||
t.equal(formatDate('M', date), 'May'); | ||
t.equal(formatDate('M', '2014-08-01 00:00:00'), 'Aug'); | ||
t.equal(formatDate('M', '2014/08/01 00:00:00'), 'Aug'); | ||
@@ -135,3 +135,3 @@ t.end(); | ||
t.equal(formatDate('a', date), 'am'); | ||
t.equal(formatDate('a', '2014-05-28 23:00:00'), 'pm'); | ||
t.equal(formatDate('a', '2014/05/28 23:00:00'), 'pm'); | ||
@@ -143,3 +143,3 @@ t.end(); | ||
t.equal(formatDate('A', date), 'AM'); | ||
t.equal(formatDate('A', '2014-05-28 23:00:00'), 'PM'); | ||
t.equal(formatDate('A', '2014/05/28 23:00:00'), 'PM'); | ||
@@ -151,3 +151,3 @@ t.end(); | ||
t.equal(formatDate('g', date), '9'); | ||
t.equal(formatDate('g', '2014-05-28 17:00:00'), '5'); | ||
t.equal(formatDate('g', '2014/05/28 17:00:00'), '5'); | ||
@@ -159,3 +159,3 @@ t.end(); | ||
t.equal(formatDate('G', date), '9'); | ||
t.equal(formatDate('G', '2014-05-28 17:00:00'), '17'); | ||
t.equal(formatDate('G', '2014/05/28 17:00:00'), '17'); | ||
@@ -167,3 +167,3 @@ t.end(); | ||
t.equal(formatDate('h', date), '09'); | ||
t.equal(formatDate('g', '2014-05-28 17:00:00'), '5'); | ||
t.equal(formatDate('g', '2014/05/28 17:00:00'), '5'); | ||
@@ -175,3 +175,3 @@ t.end(); | ||
t.equal(formatDate('H', date), '09'); | ||
t.equal(formatDate('H', '2014-05-28 17:00:00'), '17'); | ||
t.equal(formatDate('H', '2014/05/28 17:00:00'), '17'); | ||
@@ -182,4 +182,4 @@ t.end(); | ||
test('minutes, with leading zero: i', function(t) { | ||
t.equal(formatDate('i', '2014-05-28 17:01:00'), '01'); | ||
t.equal(formatDate('i', '2014-05-28 17:30:00'), '30'); | ||
t.equal(formatDate('i', '2014/05/28 17:01:00'), '01'); | ||
t.equal(formatDate('i', '2014/05/28 17:30:00'), '30'); | ||
@@ -190,6 +190,6 @@ t.end(); | ||
test('seconds, with leading zero: s', function(t) { | ||
t.equal(formatDate('s', '2014-05-28 17:00:01'), '01'); | ||
t.equal(formatDate('s', '2014-05-28 17:00:30'), '30'); | ||
t.equal(formatDate('s', '2014/05/28 17:00:01'), '01'); | ||
t.equal(formatDate('s', '2014/05/28 17:00:30'), '30'); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18200
164
308