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

daylight

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

daylight - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

.travis.yml

4

daylight.js

@@ -180,3 +180,3 @@ if ( typeof module !== 'undefined' ) {

case 'g':
return date.getHours() == 0 ? 12 : date.getHours() % 12;
return date.getHours() === 0 ? 12 : date.getHours() % 12;

@@ -189,3 +189,3 @@ // 24-hour format, no leading zero

case 'h':
var h = date.getHours() == 0 ? 12 : date.getHours() % 12;
var h = date.getHours() === 0 ? 12 : date.getHours() % 12;
return h < 10 ? '0' + h : h;

@@ -192,0 +192,0 @@

@@ -1,1 +0,1 @@

function daylight(a,b){if(!(b instanceof Date))try{b="string"==typeof b?new Date(Date.parse(b)):new Date(b)}catch(c){throw Error(c)}var d="",e=!1;return a.split("").forEach(function(a){return"\\"!==a||e?e?(d+=a,e=!1,void 0):(d+=_translate(a,b),void 0):(e=!0,void 0)}),d}function _translate(a,b){b instanceof Date||(b=new Date(b));var c=function(a,b){switch("undefined"==typeof b&&(b=!1),a.getDay()){case 0:return b?"Sun":"Sunday";case 1:return b?"Mon":"Monday";case 2:return b?"Tue":"Tuesday";case 3:return b?"Wed":"Wednesday";case 4:return b?"Thu":"Thursday";case 5:return b?"Fri":"Friday";case 6:return b?"Sat":"Saturday";default:return null}},d=function(a,b){switch("undefined"==typeof b&&(b=!1),a.getMonth()){case 0:return b?"Jan":"January";case 1:return b?"Feb":"February";case 2:return b?"Mar":"March";case 3:return b?"Apr":"April";case 4:return"May";case 5:return b?"Jun":"June";case 6:return b?"Jul":"July";case 7:return b?"Aug":"August";case 8:return b?"Sept":"September";case 9:return b?"Oct":"October";case 10:return b?"Nov":"November";case 11:return b?"Dec":"December";default:return null}};switch(a){case"d":var e=b.getDate();return 10>e?"0"+e:e;case"D":return c(b,!0);case"j":return b.getDate();case"l":return c(b,!1);case"N":return b.getDay()+1;case"S":var e=b.getDate();return 1===e?"st":2===e||/\d2$/.test(e.toString())&&!/1\d$/.test(e.toString())?"nd":3===e||/\d3$/.test(e.toString())&&!/1\d$/.test(e.toString())?"rd":/1\d|[4567890]/.test(e.toString())?"th":null;case"w":return b.getDay();case"z":var f=new Date(b.getFullYear(),0,0),g=b-f;return Math.ceil(g/864e5);case"F":return d(b,!1);case"m":var h=b.getMonth()+1;return 10>h?"0"+h:h;case"M":return d(b,!0);case"n":return b.getMonth()+1;case"Y":return b.getFullYear();case"y":return b.getFullYear().toString().substr(2);case"a":return b.getHours()>11?"pm":"am";case"A":return b.getHours()>11?"PM":"AM";case"g":return b.getHours()%12;case"G":return b.getHours();case"h":var i=b.getHours()%12;return 10>i?"0"+i:i;case"H":var i=b.getHours();return 10>i?"0"+i:i;case"i":var j=b.getMinutes();return 10>j?"0"+j:j;case"s":var k=b.getSeconds();return 10>k?"0"+k:k;default:return a}}"undefined"!=typeof module&&(module.exports=daylight);
function daylight(a,b){if(!(b instanceof Date))if("string"==typeof b){var c=Date.parse(b);if(isNaN(c))throw Error("Cannot parse '"+b+"'");b=new Date(c)}else b=new Date(b);var d="",e=!1;return a.split("").forEach(function(a){return"\\"!==a||e?e?(d+=a,e=!1,void 0):(d+=_translate(a,b),void 0):(e=!0,void 0)}),d}function _translate(a,b){b instanceof Date||(b=new Date(b));var c=function(a,b){switch("undefined"==typeof b&&(b=!1),a.getDay()){case 0:return b?"Sun":"Sunday";case 1:return b?"Mon":"Monday";case 2:return b?"Tue":"Tuesday";case 3:return b?"Wed":"Wednesday";case 4:return b?"Thu":"Thursday";case 5:return b?"Fri":"Friday";case 6:return b?"Sat":"Saturday";default:return null}},d=function(a,b){switch("undefined"==typeof b&&(b=!1),a.getMonth()){case 0:return b?"Jan":"January";case 1:return b?"Feb":"February";case 2:return b?"Mar":"March";case 3:return b?"Apr":"April";case 4:return"May";case 5:return b?"Jun":"June";case 6:return b?"Jul":"July";case 7:return b?"Aug":"August";case 8:return b?"Sept":"September";case 9:return b?"Oct":"October";case 10:return b?"Nov":"November";case 11:return b?"Dec":"December";default:return null}};switch(a){case"d":var e=b.getDate();return 10>e?"0"+e:e;case"D":return c(b,!0);case"j":return b.getDate();case"l":return c(b,!1);case"N":return b.getDay()+1;case"S":var e=b.getDate();return 1===e?"st":2===e||/\d2$/.test(e.toString())&&!/1\d$/.test(e.toString())?"nd":3===e||/\d3$/.test(e.toString())&&!/1\d$/.test(e.toString())?"rd":/1\d|[4567890]/.test(e.toString())?"th":null;case"w":return b.getDay();case"z":var f=new Date(b.getFullYear(),0,0),g=b-f;return Math.ceil(g/864e5);case"F":return d(b,!1);case"m":var h=b.getMonth()+1;return 10>h?"0"+h:h;case"M":return d(b,!0);case"n":return b.getMonth()+1;case"Y":return b.getFullYear();case"y":return b.getFullYear().toString().substr(2);case"a":return b.getHours()>11?"pm":"am";case"A":return b.getHours()>11?"PM":"AM";case"g":return 0===b.getHours()?12:b.getHours()%12;case"G":return b.getHours();case"h":var i=0===b.getHours()?12:b.getHours()%12;return 10>i?"0"+i:i;case"H":var i=b.getHours();return 10>i?"0"+i:i;case"i":var j=b.getMinutes();return 10>j?"0"+j:j;case"s":var k=b.getSeconds();return 10>k?"0"+k:k;default:return a}}"undefined"!=typeof module&&(module.exports=daylight);
{
"name": "daylight",
"version": "0.2.2",
"version": "0.2.3",
"description": "lightweight javascript date formatting",

@@ -8,18 +8,4 @@ "main": "daylight.js",

"devDependencies": {
"tape": "^2.13.1"
"tape": "~3.0.2"
},
"testling": {
"files": "test.js",
"browsers": [
"ie/6..latest",
"chrome/22..latest",
"firefox/16..latest",
"safari/latest",
"opera/11.0..latest",
"iphone/6",
"ipad/6",
"android-browser/latest"
]
},
"scripts": {

@@ -26,0 +12,0 @@ "test": "node test.js"

# daylight
[![testling](https://ci.testling.com/malantonio/daylight.png)](https://ci.testling.com/malantonio/daylight)
[![Build Status](https://travis-ci.org/malantonio/daylight.svg)](https://travis-ci.org/malantonio/daylight)

@@ -5,0 +5,0 @@ 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.

var test = require('tape');
var formatDate = require('./daylight');
var date = '2014/05/28 09:00:00';
var date = new Date(2014, 4, 28, 23);

@@ -11,3 +11,3 @@ 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');
t.equal(formatDate('Y/m/d H:i:s', date), '2014/05/28 23:00:00');
t.end();

@@ -17,3 +17,3 @@ });

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');
t.equal(formatDate('Y-m-d\\TH:i:s', date), '2014-05-28T23:00:00');
t.end();

@@ -129,4 +129,4 @@ });

test('am or pm, lowercase: a', function(t) {
t.equal(formatDate('a', date), 'am');
t.equal(formatDate('a', '2014/05/28 23:00:00'), 'pm');
t.equal(formatDate('a', '2014/05/28 03:00:00'), 'am');
t.equal(formatDate('a', date), 'pm');

@@ -137,4 +137,4 @@ t.end();

test('AM or PM, uppercase: A', function(t) {
t.equal(formatDate('A', date), 'AM');
t.equal(formatDate('A', '2014/05/28 23:00:00'), 'PM');
t.equal(formatDate('A', '2014/05/28 03:00:00'), 'AM');
t.equal(formatDate('A', date), 'PM');

@@ -145,3 +145,3 @@ t.end();

test('twelve-hour format, no leading zero: g', function(t) {
t.equal(formatDate('g', date), '9');
t.equal(formatDate('g', date), '11');
t.equal(formatDate('g', '2014/05/28 17:00:00'), '5');

@@ -154,3 +154,3 @@ t.equal(formatDate('g', '2014/05/28 00:00:00'), '12');

test('twenty-four-hour format, no leading zero: G', function(t) {
t.equal(formatDate('G', date), '9');
t.equal(formatDate('G', date), '23');
t.equal(formatDate('G', '2014/05/28 17:00:00'), '17');

@@ -162,3 +162,3 @@

test('twelve-hour format, leading zero: h', function(t) {
t.equal(formatDate('h', date), '09');
t.equal(formatDate('h', date), '11');
t.equal(formatDate('h', '2014/05/28 17:00:00'), '05');

@@ -171,4 +171,4 @@ t.equal(formatDate('h', '2014/05/28 00:00:00'), '12');

test('twenty-four-hour format, leading zero: H', function(t) {
t.equal(formatDate('H', date), '09');
t.equal(formatDate('H', '2014/05/28 17:00:00'), '17');
t.equal(formatDate('H', date), '23');
t.equal(formatDate('H', '2014/05/28 07:00:00'), '07');

@@ -191,1 +191,9 @@ t.end();

});
test('throws Error if not parseable', function(t) {
t.throws(function() {
formatDate('a', '20140505T12:12:12');
});
t.end();
});
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