New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

strftime

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strftime - npm Package Compare versions

Comparing version 0.8.4 to 0.9.0

.tm_properties

2

bower.json
{
"name": "strftime",
"version": "0.8.4",
"version": "0.9.0",
"main": "strftime.js",

@@ -5,0 +5,0 @@ "ignore": [

@@ -6,5 +6,5 @@ {

"keywords": ["strftime", "format", "date", "time"],
"version": "0.8.4",
"version": "0.9.0",
"main": "strftime.js",
"scripts": ["strftime.js"]
}
{
"name": "strftime",
"description": "strftime for JavaScript",
"version": "0.8.4",
"version": "0.9.0",
"homepage": "http://samhuri.net/proj/strftime",

@@ -11,3 +11,4 @@ "author": "Sami Samhuri <sami@samhuri.net>",

"Rob Colburn <rob@robcolburn.com> (http://robcolburn.com/)",
"Ryan Stafford (http://droffats.net/)"
"Ryan Stafford (http://droffats.net/)",
"Alexandr Nikitin <nikitin.alexandr.a@gmail.com>"
],

@@ -14,0 +15,0 @@ "repository": {

strftime
========
strftime for JavaScript, works in Node.js and browsers, supports localization.
Most standard specifiers from C are supported as well as some other extensions
from Ruby.
strftime for JavaScript. Works in (at least) node.js and browsers. Supports localization and timezones. Most standard specifiers from C are supported as well as some other extensions from Ruby.

@@ -12,9 +10,28 @@

npm install strftime
[node](https://nodejs.org):
npm install strftime
[bower](http://bower.io):
bower install strftime
[component](https://github.com/componentjs/component):
component install samsonjs/strftime
Or you can copy [strftime.js](https://github.com/samsonjs/strftime/blob/master/strftime.js) wherever you want to use it, whether that's with a &lt;script&gt; tag or `require` or anything else.
The New API in 0.9
==================
The current version, 0.9, deprecates the older API that exported several functions: `strftimeTZ`, `strftimeUTC`, and `localizedStrftime`. In addition to this the exported function referenced itself as `require('strftime').strftime` or `window.strftime.strftime` for consistency with the other functions. *These functions are deprecated in 0.9 and will be removed in 1.0.*
Now you only need the single object exported and you can create a specialized version of it using the functions `utc()`, `localize(locale)`, and `timezone(offset)`. You can no longer pass in a timezone or locale on each call to `strftime` which is a regression. If you need this let me know and we will add it back into the API.
Usage
=====
var strftime = require('strftime')
var strftime = require('strftime') // not required in browsers
console.log(strftime('%B %d, %Y %H:%M:%S')) // => April 28, 2011 18:21:08

@@ -26,31 +43,36 @@ console.log(strftime('%F %T', new Date(1307472705067))) // => 2011-06-07 18:51:45

var strftime = require('strftime')
var strftime = require('strftime') // not required in browsers
var it_IT = {
days: [ 'domenica', 'lunedi', 'martedi', 'mercoledi', 'giovedi', 'venerdi', 'sabato' ],
shortDays: [ 'dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab' ],
months: [ 'gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio',
'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre' ],
shortMonths: [ 'gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago',
'set', 'ott', 'nov', 'dic' ],
days: ['domenica', 'lunedi', 'martedi', 'mercoledi', 'giovedi', 'venerdi', 'sabato'],
shortDays: ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'],
months: ['gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'],
shortMonths: ['gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic'],
AM: 'AM',
PM: 'PM'
PM: 'PM',
am: 'am',
pm: 'pm',
formats: {
D: '%m/%d/%y',
F: '%Y-%m-%d',
R: '%H:%M',
X: '%T',
c: '%a %b %d %X %Y',
r: '%I:%M:%S %p',
T: '%H:%M:%S',
v: '%e-%b-%Y',
x: '%D'
}
}
console.log(strftime('%B %d, %Y %H:%M:%S', it_IT)) // => aprile 28, 2011 18:21:08
console.log(strftime('%B %d, %Y %H:%M:%S', new Date(1307472705067), it_IT)) // => giugno 7, 2011 18:51:45
var strftimeIT = strftime.localize(it_IT)
console.log(strftimeIT('%B %d, %Y %H:%M:%S')) // => aprile 28, 2011 18:21:08
console.log(strftimeIT('%B %d, %Y %H:%M:%S', new Date(1307472705067))) // => giugno 7, 2011 18:51:45
And if you don't want to pass a localization object every time you can get a localized `strftime` function like so:
var strftime = require('strftime')
var it_IT = { /* same as above */ }
var strftime_IT = strftime.localizedStrftime(it_IT)
console.log(strftime_IT('%B %d, %Y %H:%M:%S')) // aprile 28, 2011 18:21:08
Time zones can be passed in as an offset from GMT in minutes.
var strftimeTZ = require('strftime').strftimeTZ
console.log(strftimeTZ('%B %d, %y %H:%M:%S', new Date(1307472705067), -420)) // => June 07, 11 11:51:45
console.log(strftimeTZ('%F %T', new Date(1307472705067), 120)) // => 2011-06-07 20:51:45
var strftime = require('strftime') // not required in browsers
var strftimePDT = strftime.timezone(-420)
var strftimeCEST = strftime.timezone(120)
console.log(strftimePDT('%B %d, %y %H:%M:%S', new Date(1307472705067))) // => June 07, 11 11:51:45
console.log(strftimeCEST('%F %T', new Date(1307472705067))) // => 2011-06-07 20:51:45

@@ -60,5 +82,7 @@

var strftimeTZ = require('strftime').strftimeTZ
console.log(strftimeTZ('', new Date(1307472705067), '-0700')) // => June 07, 11 11:51:45
console.log(strftimeTZ('%F %T', new Date(1307472705067), '+0200')) // => 2011-06-07 20:51:45
var strftime = require('strftime') // not required in browsers
var strftimePDT = strftime.timezone('-0700')
var strftimeCEST = strftime.timezone('+0200')
console.log(strftimePDT('', new Date(1307472705067))) // => June 07, 11 11:51:45
console.log(strftimeCEST('%F %T', new Date(1307472705067))) // => 2011-06-07 20:51:45

@@ -79,6 +103,7 @@

- C: AD century (year / 100), padded to 2 digits
- D: equivalent to `%m/%d/%y`
- c: equivalent to `%a %b %d %X %Y` in en-US (based on locale)
- D: equivalent to `%m/%d/%y` in en-US (based on locale)
- d: day of the month, padded to 2 digits (01-31)
- e: day of the month, padded with a leading space for single digit values (1-31)
- F: equivalent to `%Y-%m-%d`
- F: equivalent to `%Y-%m-%d` in en-US (based on locale)
- H: the hour (24-hour clock), padded to 2 digits (00-23)

@@ -95,15 +120,17 @@ - h: the same as %b (abbreviated month name)

- o: day of the month as an ordinal (without padding), e.g. 1st, 2nd, 3rd, 4th, ...
- P: "am" or "pm" in lowercase [Ruby extension]
- p: "AM" or "PM"
- R: equivalent to `%H:%M`
- r: equivalent to `%I:%M:%S %p`
- P: "am" or "pm" in lowercase (Ruby extension, based on locale)
- p: "AM" or "PM" (based on locale)
- R: equivalent to `%H:%M` in en-US (based on locale)
- r: equivalent to `%I:%M:%S %p` in en-US (based on locale)
- S: the second, padded to 2 digits (00-60)
- s: the number of seconds since the Epoch, UTC
- T: equivalent to `%H:%M:%S`
- T: equivalent to `%H:%M:%S` in en-US (based on locale)
- t: tab character
- U: week number of the year, Sunday as the first day of the week, padded to 2 digits (00-53)
- u: the weekday, Monday as the first day of the week (1-7)
- v: equivalent to `%e-%b-%Y`
- v: equivalent to `%e-%b-%Y` in en-US (based on locale)
- W: week number of the year, Monday as the first day of the week, padded to 2 digits (00-53)
- w: the weekday, Sunday as the first day of the week (0-6)
- X: equivalent to `%D` in en-US (based on locale)
- x: equivalent to `%T` in en-US (based on locale)
- Y: the year with the century

@@ -116,11 +143,5 @@ - y: the year without the century (00-99)

For more detail see `man 3 strftime` as the format specifiers should behave
identically. If behaviour differs please [file a bug](https://github.com/samsonjs/strftime/issues/new).
For more detail see `man 3 strftime` as the format specifiers should behave identically. If behaviour differs please [file a bug](https://github.com/samsonjs/strftime/issues/new).
Any specifier can be modified with `-`, `_`, `0`, or `:` as well, as in Ruby.
Using `%-` will omit any leading zeroes or spaces, `%_` will force spaces
for padding instead of the default, and `%0` will force zeroes for padding.
There's some redundancy here as `%-d` and `%e` have the same result, but it
solves some awkwardness with formats like `%l`. Using `%:` for time zone offset,
as in `%:z` will insert a colon as a delimiter.
Any specifier can be modified with `-`, `_`, `0`, or `:` as well, as in Ruby. Using `%-` will omit any leading zeroes or spaces, `%_` will force spaces for padding instead of the default, and `%0` will force zeroes for padding. There's some redundancy here as `%-d` and `%e` have the same result, but it solves some awkwardness with formats like `%l`. Using `%:` for time zone offset, as in `%:z` will insert a colon as a delimiter.

@@ -130,5 +151,7 @@ Contributors

* [Rob Colburn](https://github.com/robcolburn)
* [Cory Heslip](https://github.com/cheslip)
* [Alexandr Nikitin](https://github.com/alexandrnikitin)
* [Sami Samhuri](https://github.com/samsonjs)
* [Andrew Schaaf](https://github.com/andrewschaaf)
* [Rob Colburn](https://github.com/robcolburn)
* [Ryan Stafford](https://github.com/ryanstafford)

@@ -140,5 +163,5 @@

Copyright 2010 - 2013 Sami Samhuri sami@samhuri.net
Copyright 2010 - 2015 Sami Samhuri sami@samhuri.net
[MIT license](http://sjs.mit-license.org)

@@ -1,8 +0,11 @@

(function(){function k(c,a,b){return h(c,a,b)}function h(c,a,b,l){l=l||{};a&&!p(a)&&(b=a,a=void 0);a=a||new Date;b=b||q;b.formats=b.formats||{};var k=a.getTime(),i=l.timezone,d=typeof i;if(l.utc||d=="number"||d=="string")a=r(a);if(i){if(d=="string")var m=i[0]=="-"?-1:1,s=parseInt(i.slice(1,3),10),t=parseInt(i.slice(3,5),10),i=m*(60*s+t);d&&(a=new Date(a.getTime()+i*6E4))}return c.replace(/%([-_0:]?.)/g,function(c,d){var j,e,g;if(d.length==2){j=d[0];if(j=="-")e="";else if(j=="_")e=" ";else if(j=="0")e=
"0";else if(j==":")g=!0;else return c;d=d[1]}switch(d){case "A":return b.days[a.getDay()];case "a":return b.shortDays[a.getDay()];case "B":return b.months[a.getMonth()];case "b":return b.shortMonths[a.getMonth()];case "C":return f(Math.floor(a.getFullYear()/100),e);case "D":return h(b.formats.D||"%m/%d/%y",a,b);case "d":return f(a.getDate(),e);case "e":return f(a.getDate(),e==null?" ":e);case "F":return h(b.formats.F||"%Y-%m-%d",a,b);case "H":return f(a.getHours(),e);case "h":return b.shortMonths[a.getMonth()];
case "I":return f(n(a),e);case "j":return g=new Date(a.getFullYear(),0,1),g=Math.ceil((a.getTime()-g.getTime())/864E5),f(g,3);case "k":return f(a.getHours(),e==null?" ":e);case "L":return f(Math.floor(k%1E3),3);case "l":return f(n(a),e==null?" ":e);case "M":return f(a.getMinutes(),e);case "m":return f(a.getMonth()+1,e);case "n":return"\n";case "o":return String(a.getDate())+u(a.getDate());case "P":return a.getHours()<12?b.am:b.pm;case "p":return a.getHours()<12?b.AM:b.PM;case "R":return h(b.formats.R||
"%H:%M",a,b);case "r":return h(b.formats.r||"%I:%M:%S %p",a,b);case "S":return f(a.getSeconds(),e);case "s":return Math.floor(k/1E3);case "T":return h(b.formats.T||"%H:%M:%S",a,b);case "t":return"\t";case "U":return f(o(a,"sunday"),e);case "u":return g=a.getDay(),g==0?7:g;case "v":return h(b.formats.v||"%e-%b-%Y",a,b);case "W":return f(o(a,"monday"),e);case "w":return a.getDay();case "Y":return a.getFullYear();case "y":return g=String(a.getFullYear()),g.slice(g.length-2);case "Z":return l.utc?"GMT":
(g=a.toString().match(/\(([\w\s]+)\)/))&&g[1]||"";case "z":return l.utc?g?"+00:00":"+0000":(j=typeof i=="number"?i:-a.getTimezoneOffset(),(j<0?"-":"+")+f(Math.floor(Math.abs(j)/60))+(g?":":"")+f(Math.abs(j)%60));default:return d}})}function r(c){var a=c.getUTCFullYear(),c=new Date(a,c.getUTCMonth(),c.getUTCDate(),c.getUTCHours(),c.getUTCMinutes(),c.getUTCSeconds(),c.getUTCMilliseconds());c.getFullYear()!=a&&c.setFullYear(a);return c}function p(c){for(var a=0,b=m.length,a=0;a<b;++a)if(typeof c[m[a]]!=
"function")return!1;return!0}function f(c,a,b){typeof a==="number"&&(b=a,a="0");a==null&&(a="0");b=b||2;c=String(c);if(a)for(;c.length<b;)c=a+c;return c}function n(c){c=c.getHours();c==0?c=12:c>12&&(c-=12);return c}function u(c){var a=c%10;c%=100;if(c>=11&&c<=13||a===0||a>=4)return"th";switch(a){case 1:return"st";case 2:return"nd";case 3:return"rd"}}function o(c,a){var a=a||"sunday",b=c.getDay();a=="monday"&&(b==0?b=6:b--);var d=new Date(c.getFullYear(),0,1);return Math.floor(((c-d)/864E5+7-b)/7)}
var d;d=typeof module!=="undefined"?module.exports=k:function(){return this||(0,eval)("this")}();var q={days:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),shortDays:"Sun Mon Tue Wed Thu Fri Sat".split(" "),months:"January February March April May June July August September October November December".split(" "),shortMonths:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),AM:"AM",PM:"PM",am:"am",pm:"pm"};d.strftime=k;d.strftimeTZ=k.strftimeTZ=function(c,a,b,d){if((typeof b==
"number"||typeof b=="string")&&d==null)d=b,b=void 0;return h(c,a,b,{timezone:d})};d.strftimeUTC=k.strftimeUTC=function(c,a,b){return h(c,a,b,{utc:!0})};d.localizedStrftime=k.localizedStrftime=function(c){return function(a,b){return h(a,b,c)}};var m=["getTime","getTimezoneOffset","getDay","getDate","getMonth","getFullYear","getYear","getHours","getMinutes","getSeconds"]})();
(function(){function k(a,e){s[a]||(typeof console!=="undefined"&&typeof console.warn=="function"&&console.warn("[WARNING] "+a+" is deprecated and will be removed in version 1.0. Instead, use `"+e+"`."),s[a]=!0)}function t(a){a.localize=g.localize.bind(g);a.timezone=g.timezone.bind(g);a.utc=g.utc.bind(g)}function r(a,e,c){c&&k("`"+i+"(format, date, locale)`",i+".localize(locale)(format, [date])");return(c?g.localize(c):g)(a,e)}function u(a,e,c){c?k("`"+i+".strftime(format, date, locale)`",i+".localize(locale)(format, [date])"):
k("`"+i+".strftime(format, [date])`",i+"(format, [date])");return(c?g.localize(c):g)(a,e)}function p(a,e,c){function m(a,b,h,c){for(var d="",f=null,e=!1,i=a.length,j=!1,o=0;o<i;o++){var n=a.charCodeAt(o);if(e===!0)if(n===45)f="";else if(n===95)f=" ";else if(n===48)f="0";else if(n===58)j=!0;else{switch(n){case 65:d+=h.days[b.getDay()];break;case 66:d+=h.months[b.getMonth()];break;case 67:d+=l(Math.floor(b.getFullYear()/100),f);break;case 68:d+=m(h.formats.D,b,h,c);break;case 70:d+=m(h.formats.F,b,
h,c);break;case 72:d+=l(b.getHours(),f);break;case 73:d+=l(v(b.getHours()),f);break;case 76:d+=Math.floor(c%1E3)>99?Math.floor(c%1E3):Math.floor(c%1E3)>9?"0"+Math.floor(c%1E3):"00"+Math.floor(c%1E3);break;case 77:d+=l(b.getMinutes(),f);break;case 80:d+=b.getHours()<12?h.am:h.pm;break;case 82:d+=m(h.formats.R,b,h,c);break;case 83:d+=l(b.getSeconds(),f);break;case 84:d+=m(h.formats.T,b,h,c);break;case 85:d+=l(w(b,"sunday"),f);break;case 87:d+=l(w(b,"monday"),f);break;case 88:d+=m(h.formats.X,b,h,c);
break;case 89:d+=b.getFullYear();break;case 90:k&&g===0?d+="GMT":(f=b.toString().match(/\((\w+)\)/),d+=f&&f[1]||"");break;case 97:d+=h.shortDays[b.getDay()];break;case 98:d+=h.shortMonths[b.getMonth()];break;case 99:d+=m(h.formats.c,b,h,c);break;case 100:d+=l(b.getDate(),f);break;case 101:d+=l(b.getDate(),f==null?" ":f);break;case 104:d+=h.shortMonths[b.getMonth()];break;case 106:f=new Date(b.getFullYear(),0,1);f=Math.ceil((b.getTime()-f.getTime())/864E5);d+=f>99?f:f>9?"0"+f:"00"+f;break;case 107:d+=
l(b.getHours(),f==null?" ":f);break;case 108:d+=l(v(b.getHours()),f==null?" ":f);break;case 109:d+=l(b.getMonth()+1,f);break;case 110:d+="\n";break;case 111:d+=String(b.getDate())+z(b.getDate());break;case 112:d+=b.getHours()<12?h.AM:h.PM;break;case 114:d+=m(h.formats.r,b,h,c);break;case 115:d+=Math.floor(c/1E3);break;case 116:d+="\t";break;case 117:f=b.getDay();d+=f===0?7:f;break;case 118:d+=m(h.formats.v,b,h,c);break;case 119:d+=b.getDay();break;case 120:d+=m(h.formats.x,b,h,c);break;case 121:d+=
(""+b.getFullYear()).slice(2);break;case 122:k&&g===0?d+=j?"+00:00":"+0000":(f=g!==0?g/6E4:-b.getTimezoneOffset(),e=j?":":"",n=Math.abs(f%60),d+=(f<0?"-":"+")+l(Math.floor(Math.abs(f/60)))+e+l(n));break;default:d+=a[o]}f=null;e=!1}else n===37?e=!0:d+=a[o]}return d}var i=a||x,g=e||0,k=c||!1,j=0,q,a=function(a,b){var c;if(b)c=b.getTime(),k&&(b=new Date(b.getTime()+(b.getTimezoneOffset()||0)*6E4+g));else{var e=Date.now();e>j&&(j=e,q=new Date(j),c=j,k&&(q=new Date(j+(q.getTimezoneOffset()||0)*6E4+g)));
b=q}return m(a,b,i,c)};a.localize=function(a){return new p(a||i,g,k)};a.timezone=function(a){var b=g,c=k,e=typeof a;if(e==="number"||e==="string")c=!0,e==="string"?(b=a[0]==="-"?-1:1,e=parseInt(a.slice(1,3),10),a=parseInt(a.slice(3,5),10),b=b*(60*e+a)*6E4):e==="number"&&(b=a*6E4);return new p(i,b,c)};a.utc=function(){return new p(i,g,!0)};return a}function l(a,e){if(e===""||a>9)return a;e==null&&(e="0");return e+a}function v(a){if(a===0)return 12;else if(a>12)return a-12;return a}function w(a,e){var e=
e||"sunday",c=a.getDay();e==="monday"&&(c===0?c=6:c--);var g=new Date(a.getFullYear(),0,1);return Math.floor(((a-g)/864E5+7-c)/7)}function z(a){var e=a%10;a%=100;if(a>=11&&a<=13||e===0||e>=4)return"th";switch(e){case 1:return"st";case 2:return"nd";case 3:return"rd"}}var x={days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October",
"November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{D:"%m/%d/%y",F:"%Y-%m-%d",R:"%H:%M",T:"%H:%M:%S",X:"%T",c:"%a %b %d %X %Y",r:"%I:%M:%S %p",v:"%e-%b-%Y",x:"%D"}},g=new p(x,0,!1),y=typeof module!=="undefined",j;y?(j=module.exports=r,j.strftime=u):(j=function(){return this||(0,eval)("this")}(),j.strftime=r);var i=y?"require('strftime')":"strftime",s={};j.strftimeTZ=function(a,e,c,j){if((typeof c=="number"||
typeof c=="string")&&j==null)j=c,c=void 0;c?k("`"+i+".strftimeTZ(format, date, locale, tz)`",i+".timezone(tz).localize(locale)(format, [date])"):k("`"+i+".strftimeTZ(format, date, tz)`",i+".timezone(tz)(format, [date])");return(c?g.timezone(j).localize(c):g).timezone(j)(a,e)};j.strftimeUTC=function(a,e,c){c?k("`"+i+".strftimeUTC(format, date, locale)`",i+".localize(locale).utc()(format, [date])"):k("`"+i+".strftimeUTC(format, [date])`",i+".utc()(format, [date])");return(c?g.utc().localize(c):g).utc()(a,
e)};j.localizedStrftime=function(a){k("`"+i+".localizedStrftime(locale)`",i+".localize(locale)");return g.localize(a)};t(r);t(u);if(typeof Date.now!=="function")Date.now=function(){return+new Date}})();

@@ -6,3 +6,3 @@ //

//
// Copyright 2010 - 2013 Sami Samhuri <sami@samhuri.net>
// Copyright 2010 - 2015 Sami Samhuri <sami@samhuri.net>
//

@@ -15,372 +15,607 @@ // MIT License

//// Where to export the API
var namespace;
var DefaultLocale = {
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
AM: 'AM',
PM: 'PM',
am: 'am',
pm: 'pm',
formats: {
D: '%m/%d/%y',
F: '%Y-%m-%d',
R: '%H:%M',
T: '%H:%M:%S',
X: '%T',
c: '%a %b %d %X %Y',
r: '%I:%M:%S %p',
v: '%e-%b-%Y',
x: '%D'
}
},
defaultStrftime = new Strftime(DefaultLocale, 0, false),
isCommonJS = typeof module !== 'undefined',
namespace;
// CommonJS / Node module
if (typeof module !== 'undefined') {
namespace = module.exports = strftime;
}
// CommonJS / Node module
if (isCommonJS) {
namespace = module.exports = adaptedStrftime;
namespace.strftime = deprecatedStrftime;
}
// Browsers and other environments
else {
// Get the global object. Works in ES3, ES5, and ES5 strict mode.
namespace = (function() { return this || (1,eval)('this'); }());
namespace.strftime = adaptedStrftime;
}
// Browsers and other environments
else {
// Get the global object. Works in ES3, ES5, and ES5 strict mode.
namespace = (function(){ return this || (1,eval)('this') }());
}
// Deprecated API, to be removed in v1.0
var _require = isCommonJS ? "require('strftime')" : "strftime";
var _deprecationWarnings = {};
function deprecationWarning(name, instead) {
if (!_deprecationWarnings[name]) {
if (typeof console !== 'undefined' && typeof console.warn == 'function') {
console.warn("[WARNING] " + name + " is deprecated and will be removed in version 1.0. Instead, use `" + instead + "`.");
}
_deprecationWarnings[name] = true;
}
}
function words(s) { return (s || '').split(' '); }
namespace.strftimeTZ = deprecatedStrftimeTZ;
namespace.strftimeUTC = deprecatedStrftimeUTC;
namespace.localizedStrftime = deprecatedStrftimeLocalized;
var DefaultLocale =
{ days: words('Sunday Monday Tuesday Wednesday Thursday Friday Saturday')
, shortDays: words('Sun Mon Tue Wed Thu Fri Sat')
, months: words('January February March April May June July August September October November December')
, shortMonths: words('Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec')
, AM: 'AM'
, PM: 'PM'
, am: 'am'
, pm: 'pm'
};
// Adapt the old API while preserving the new API.
function adaptForwards(fn) {
fn.localize = defaultStrftime.localize.bind(defaultStrftime);
fn.timezone = defaultStrftime.timezone.bind(defaultStrftime);
fn.utc = defaultStrftime.utc.bind(defaultStrftime);
}
namespace.strftime = strftime;
function strftime(fmt, d, locale) {
return _strftime(fmt, d, locale);
}
adaptForwards(adaptedStrftime);
function adaptedStrftime(fmt, d, locale) {
// d and locale are optional, check if this is (format, locale)
if (d && d.days) {
locale = d;
d = undefined;
}
if (locale) {
deprecationWarning("`" + _require + "(format, [date], [locale])`", "var s = " + _require + ".localize(locale); s(format, [date])");
}
var strftime = locale ? defaultStrftime.localize(locale) : defaultStrftime;
return strftime(fmt, d);
}
// locale is optional
namespace.strftimeTZ = strftime.strftimeTZ = strftimeTZ;
function strftimeTZ(fmt, d, locale, timezone) {
if ((typeof locale == 'number' || typeof locale == 'string') && timezone == null) {
timezone = locale;
locale = undefined;
adaptForwards(deprecatedStrftime);
function deprecatedStrftime(fmt, d, locale) {
if (locale) {
deprecationWarning("`" + _require + ".strftime(format, [date], [locale])`", "var s = " + _require + ".localize(locale); s(format, [date])");
}
else {
deprecationWarning("`" + _require + ".strftime(format, [date])`", _require + "(format, [date])");
}
var strftime = locale ? defaultStrftime.localize(locale) : defaultStrftime;
return strftime(fmt, d);
}
return _strftime(fmt, d, locale, { timezone: timezone });
}
namespace.strftimeUTC = strftime.strftimeUTC = strftimeUTC;
function strftimeUTC(fmt, d, locale) {
return _strftime(fmt, d, locale, { utc: true });
}
function deprecatedStrftimeTZ(fmt, d, locale, timezone) {
// locale is optional, check if this is (format, date, timezone)
if ((typeof locale == 'number' || typeof locale == 'string') && timezone == null) {
timezone = locale;
locale = undefined;
}
namespace.localizedStrftime = strftime.localizedStrftime = localizedStrftime;
function localizedStrftime(locale) {
return function(fmt, d, options) {
return strftime(fmt, d, locale, options);
if (locale) {
deprecationWarning("`" + _require + ".strftimeTZ(format, date, locale, tz)`", "var s = " + _require + ".localize(locale).timezone(tz); s(format, [date])` or `var s = " + _require + ".localize(locale); s.timezone(tz)(format, [date])");
}
else {
deprecationWarning("`" + _require + ".strftimeTZ(format, date, tz)`", "var s = " + _require + ".timezone(tz); s(format, [date])` or `" + _require + ".timezone(tz)(format, [date])");
}
var strftime = (locale ? defaultStrftime.localize(locale) : defaultStrftime).timezone(timezone);
return strftime(fmt, d);
};
}
// d, locale, and options are optional, but you can't leave
// holes in the argument list. If you pass options you have to pass
// in all the preceding args as well.
//
// options:
// - locale [object] an object with the same structure as DefaultLocale
// - timezone [number] timezone offset in minutes from GMT
function _strftime(fmt, d, locale, options) {
options = options || {};
var utcStrftime = defaultStrftime.utc();
function deprecatedStrftimeUTC(fmt, d, locale) {
if (locale) {
deprecationWarning("`" + _require + ".strftimeUTC(format, date, locale)`", "var s = " + _require + ".localize(locale).utc(); s(format, [date])");
}
else {
deprecationWarning("`" + _require + ".strftimeUTC(format, [date])`", "var s = " + _require + ".utc(); s(format, [date])");
}
var strftime = locale ? utcStrftime.localize(locale) : utcStrftime;
return strftime(fmt, d);
};
// d and locale are optional so check if d is really the locale
if (d && !quacksLikeDate(d)) {
locale = d;
d = undefined;
function deprecatedStrftimeLocalized(locale) {
deprecationWarning("`" + _require + ".localizedStrftime(locale)`", _require + ".localize(locale)");
return defaultStrftime.localize(locale);
};
// End of deprecated API
// Polyfill Date.now for old browsers.
if (typeof Date.now !== 'function') {
Date.now = function() {
return +new Date();
};
}
d = d || new Date();
locale = locale || DefaultLocale;
locale.formats = locale.formats || {};
function Strftime(locale, customTimezoneOffset, useUtcTimezone) {
var _locale = locale || DefaultLocale,
_customTimezoneOffset = customTimezoneOffset || 0,
_useUtcBasedDate = useUtcTimezone || false,
// Hang on to this Unix timestamp because we might mess with it directly below.
var timestamp = d.getTime();
// we store unix timestamp value here to not create new Date() each iteration (each millisecond)
// Date.now() is 2 times faster than new Date()
// while millisecond precise is enough here
// this could be very helpful when strftime triggered a lot of times one by one
_cachedDateTimestamp = 0,
_cachedDate;
var tz = options.timezone;
var tzType = typeof tz;
function _strftime(format, date) {
var timestamp;
if (options.utc || tzType == 'number' || tzType == 'string') {
d = dateToUTC(d);
}
if (!date) {
var currentTimestamp = Date.now();
if (currentTimestamp > _cachedDateTimestamp) {
_cachedDateTimestamp = currentTimestamp;
_cachedDate = new Date(_cachedDateTimestamp);
if (tz) {
// ISO 8601 format timezone string, [-+]HHMM
//
// Convert to the number of minutes and it'll be applied to the date below.
if (tzType == 'string') {
var sign = tz[0] == '-' ? -1 : 1;
var hours = parseInt(tz.slice(1, 3), 10);
var mins = parseInt(tz.slice(3, 5), 10);
tz = sign * ((60 * hours) + mins);
}
timestamp = _cachedDateTimestamp;
if (tzType) {
d = new Date(d.getTime() + (tz * 60000));
}
}
if (_useUtcBasedDate) {
// how to avoid duplication of date instantiation for utc here?
// we tied to getTimezoneOffset of the current date
_cachedDate = new Date(_cachedDateTimestamp + getTimestampToUtcOffsetFor(_cachedDate) + _customTimezoneOffset);
}
}
date = _cachedDate;
}
else {
timestamp = date.getTime();
// Most of the specifiers supported by C's strftime, and some from Ruby.
// Some other syntax extensions from Ruby are supported: %-, %_, and %0
// to pad with nothing, space, or zero (respectively).
return fmt.replace(/%([-_0:]?.)/g, function(_, c) {
var mod, padding, ext;
if (_useUtcBasedDate) {
date = new Date(date.getTime() + getTimestampToUtcOffsetFor(date) + _customTimezoneOffset);
}
}
if (c.length == 2) {
mod = c[0];
// omit padding
if (mod == '-') {
padding = '';
return _processFormat(format, date, _locale, timestamp);
}
// pad with space
else if (mod == '_') {
padding = ' ';
}
// pad with zero
else if (mod == '0') {
padding = '0';
}
else if (mod == ":") {
ext = true;
}
else {
// unrecognized, return the format
return _;
}
c = c[1];
}
switch (c) {
function _processFormat(format, date, locale, timestamp) {
var resultString = '',
padding = null,
isInScope = false,
length = format.length,
extendedTZ = false;
// Examples for new Date(0) in GMT
for (var i = 0; i < length; i++) {
// 'Thursday'
case 'A': return locale.days[d.getDay()];
var currentCharCode = format.charCodeAt(i);
// 'Thu'
case 'a': return locale.shortDays[d.getDay()];
if (isInScope === true) {
// '-'
if (currentCharCode === 45) {
padding = '';
continue;
}
// '_'
else if (currentCharCode === 95) {
padding = ' ';
continue;
}
// '0'
else if (currentCharCode === 48) {
padding = '0';
continue;
}
// ':'
else if (currentCharCode === 58) {
extendedTZ = true;
continue;
}
// 'January'
case 'B': return locale.months[d.getMonth()];
switch (currentCharCode) {
// 'Jan'
case 'b': return locale.shortMonths[d.getMonth()];
// Examples for new Date(0) in GMT
// '19'
case 'C': return pad(Math.floor(d.getFullYear() / 100), padding);
// 'Thursday'
// case 'A':
case 65:
resultString += locale.days[date.getDay()];
break;
// '01/01/70'
case 'D': return _strftime(locale.formats.D || '%m/%d/%y', d, locale);
// 'January'
// case 'B':
case 66:
resultString += locale.months[date.getMonth()];
break;
// '01'
case 'd': return pad(d.getDate(), padding);
// '19'
// case 'C':
case 67:
resultString += padTill2(Math.floor(date.getFullYear() / 100), padding);
break;
// '01'
case 'e': return pad(d.getDate(), padding == null ? ' ' : padding);
// '01/01/70'
// case 'D':
case 68:
resultString += _processFormat(locale.formats.D, date, locale, timestamp);
break;
// '1970-01-01'
case 'F': return _strftime(locale.formats.F || '%Y-%m-%d', d, locale);
// '1970-01-01'
// case 'F':
case 70:
resultString += _processFormat(locale.formats.F, date, locale, timestamp);
break;
// '00'
case 'H': return pad(d.getHours(), padding);
// '00'
// case 'H':
case 72:
resultString += padTill2(date.getHours(), padding);
break;
// 'Jan'
case 'h': return locale.shortMonths[d.getMonth()];
// '12'
// case 'I':
case 73:
resultString += padTill2(hours12(date.getHours()), padding);
break;
// '12'
case 'I': return pad(hours12(d), padding);
// '000'
// case 'L':
case 76:
resultString += padTill3(Math.floor(timestamp % 1000));
break;
// '000'
case 'j':
var y = new Date(d.getFullYear(), 0, 1);
var day = Math.ceil((d.getTime() - y.getTime()) / (1000 * 60 * 60 * 24));
return pad(day, 3);
// '00'
// case 'M':
case 77:
resultString += padTill2(date.getMinutes(), padding);
break;
// ' 0'
case 'k': return pad(d.getHours(), padding == null ? ' ' : padding);
// 'am'
// case 'P':
case 80:
resultString += date.getHours() < 12 ? locale.am : locale.pm;
break;
// '000'
case 'L': return pad(Math.floor(timestamp % 1000), 3);
// '00:00'
// case 'R':
case 82:
resultString += _processFormat(locale.formats.R, date, locale, timestamp);
break;
// '12'
case 'l': return pad(hours12(d), padding == null ? ' ' : padding);
// '00'
// case 'S':
case 83:
resultString += padTill2(date.getSeconds(), padding);
break;
// '00'
case 'M': return pad(d.getMinutes(), padding);
// '00:00:00'
// case 'T':
case 84:
resultString += _processFormat(locale.formats.T, date, locale, timestamp);
break;
// '01'
case 'm': return pad(d.getMonth() + 1, padding);
// '00'
// case 'U':
case 85:
resultString += padTill2(weekNumber(date, 'sunday'), padding);
break;
// '\n'
case 'n': return '\n';
// '00'
// case 'W':
case 87:
resultString += padTill2(weekNumber(date, 'monday'), padding);
break;
// '1st'
case 'o': return String(d.getDate()) + ordinal(d.getDate());
// '16:00:00'
// case 'X':
case 88:
resultString += _processFormat(locale.formats.X, date, locale, timestamp);
break;
// 'am'
case 'P': return d.getHours() < 12 ? locale.am : locale.pm;
// '1970'
// case 'Y':
case 89:
resultString += date.getFullYear();
break;
// 'AM'
case 'p': return d.getHours() < 12 ? locale.AM : locale.PM;
// 'GMT'
// case 'Z':
case 90:
if (_useUtcBasedDate && _customTimezoneOffset === 0) {
resultString += "GMT";
}
else {
// fixme optimize
var tzString = date.toString().match(/\((\w+)\)/);
resultString += tzString && tzString[1] || '';
}
break;
// '00:00'
case 'R': return _strftime(locale.formats.R || '%H:%M', d, locale);
// 'Thu'
// case 'a':
case 97:
resultString += locale.shortDays[date.getDay()];
break;
// '12:00:00 AM'
case 'r': return _strftime(locale.formats.r || '%I:%M:%S %p', d, locale);
// 'Jan'
// case 'b':
case 98:
resultString += locale.shortMonths[date.getMonth()];
break;
// '00'
case 'S': return pad(d.getSeconds(), padding);
// ''
// case 'c':
case 99:
resultString += _processFormat(locale.formats.c, date, locale, timestamp);
break;
// '0'
case 's': return Math.floor(timestamp / 1000);
// '01'
// case 'd':
case 100:
resultString += padTill2(date.getDate(), padding);
break;
// '00:00:00'
case 'T': return _strftime(locale.formats.T || '%H:%M:%S', d, locale);
// ' 1'
// case 'e':
case 101:
resultString += padTill2(date.getDate(), padding == null ? ' ' : padding);
break;
// '\t'
case 't': return '\t';
// 'Jan'
// case 'h':
case 104:
resultString += locale.shortMonths[date.getMonth()];
break;
// '00'
case 'U': return pad(weekNumber(d, 'sunday'), padding);
// '000'
// case 'j':
case 106:
var y = new Date(date.getFullYear(), 0, 1);
var day = Math.ceil((date.getTime() - y.getTime()) / (1000 * 60 * 60 * 24));
resultString += padTill3(day);
break;
// '4'
case 'u':
var day = d.getDay();
return day == 0 ? 7 : day; // 1 - 7, Monday is first day of the week
// ' 0'
// case 'k':
case 107:
resultString += padTill2(date.getHours(), padding == null ? ' ' : padding);
break;
// ' 1-Jan-1970'
case 'v': return _strftime(locale.formats.v || '%e-%b-%Y', d, locale);
// '12'
// case 'l':
case 108:
resultString += padTill2(hours12(date.getHours()), padding == null ? ' ' : padding);
break;
// '00'
case 'W': return pad(weekNumber(d, 'monday'), padding);
// '01'
// case 'm':
case 109:
resultString += padTill2(date.getMonth() + 1, padding);
break;
// '4'
case 'w': return d.getDay(); // 0 - 6, Sunday is first day of the week
// '\n'
// case 'n':
case 110:
resultString += '\n';
break;
// '1970'
case 'Y': return d.getFullYear();
// '1st'
// case 'o':
case 111:
resultString += String(date.getDate()) + ordinal(date.getDate());
break;
// '70'
case 'y':
var y = String(d.getFullYear());
return y.slice(y.length - 2);
// 'AM'
// case 'p':
case 112:
resultString += date.getHours() < 12 ? locale.AM : locale.PM;
break;
// 'GMT'
case 'Z':
if (options.utc) {
return "GMT";
}
else {
var tzString = d.toString().match(/\(([\w\s]+)\)/);
return tzString && tzString[1] || '';
}
// '12:00:00 AM'
// case 'r':
case 114:
resultString += _processFormat(locale.formats.r, date, locale, timestamp);
break;
// '+0000'
case 'z':
if (options.utc) {
return ext ? "+00:00" : "+0000";
}
else {
var off = typeof tz == 'number' ? tz : -d.getTimezoneOffset();
var sep = ext ? ":" : ""; // separator for extended offset
return (off < 0 ? '-' : '+') + pad(Math.floor(Math.abs(off) / 60)) + sep + pad(Math.abs(off) % 60);
}
// '0'
// case 's':
case 115:
resultString += Math.floor(timestamp / 1000);
break;
default: return c;
}
});
}
// '\t'
// case 't':
case 116:
resultString += '\t';
break;
function dateToUTC(d) {
var year = d.getUTCFullYear();
var date = new Date(
year,
d.getUTCMonth(),
d.getUTCDate(),
d.getUTCHours(),
d.getUTCMinutes(),
d.getUTCSeconds(),
d.getUTCMilliseconds()
);
// In old dates, years is incorrectly interpreted as a 2-digit year with base 1900.
// Correct this by setting the year explicitly after the fuzzy creation process.
if (date.getFullYear() != year) {
date.setFullYear(year);
}
return date;
}
// '4'
// case 'u':
case 117:
var day = date.getDay();
resultString += day === 0 ? 7 : day;
break; // 1 - 7, Monday is first day of the week
var RequiredDateMethods = ['getTime', 'getTimezoneOffset', 'getDay', 'getDate', 'getMonth', 'getFullYear', 'getYear', 'getHours', 'getMinutes', 'getSeconds'];
function quacksLikeDate(x) {
var i = 0
, n = RequiredDateMethods.length
;
for (i = 0; i < n; ++i) {
if (typeof x[RequiredDateMethods[i]] != 'function') {
return false;
}
// ' 1-Jan-1970'
// case 'v':
case 118:
resultString += _processFormat(locale.formats.v, date, locale, timestamp);
break;
// '4'
// case 'w':
case 119:
resultString += date.getDay();
break; // 0 - 6, Sunday is first day of the week
// '12/31/69'
// case 'x':
case 120:
resultString += _processFormat(locale.formats.x, date, locale, timestamp);
break;
// '70'
// case 'y':
case 121:
resultString += ('' + date.getFullYear()).slice(2);
break;
// '+0000'
// case 'z':
case 122:
if (_useUtcBasedDate && _customTimezoneOffset === 0) {
resultString += extendedTZ ? "+00:00" : "+0000";
}
else {
var off;
if (_customTimezoneOffset !== 0) {
off = _customTimezoneOffset / (60 * 1000);
}
else {
off = -date.getTimezoneOffset();
}
var sign = off < 0 ? '-' : '+';
var sep = extendedTZ ? ':' : '';
var hours = Math.floor(Math.abs(off / 60));
var mins = Math.abs(off % 60);
resultString += sign + padTill2(hours) + sep + padTill2(mins);
}
break;
default:
resultString += format[i];
break;
}
padding = null;
isInScope = false;
continue;
}
// '%'
if (currentCharCode === 37) {
isInScope = true;
continue;
}
resultString += format[i];
}
return resultString;
}
var strftime = _strftime;
strftime.localize = function(locale) {
return new Strftime(locale || _locale, _customTimezoneOffset, _useUtcBasedDate);
};
strftime.timezone = function(timezone) {
var customTimezoneOffset = _customTimezoneOffset;
var useUtcBasedDate = _useUtcBasedDate;
var timezoneType = typeof timezone;
if (timezoneType === 'number' || timezoneType === 'string') {
useUtcBasedDate = true;
// ISO 8601 format timezone string, [-+]HHMM
if (timezoneType === 'string') {
var sign = timezone[0] === '-' ? -1 : 1,
hours = parseInt(timezone.slice(1, 3), 10),
minutes = parseInt(timezone.slice(3, 5), 10);
customTimezoneOffset = sign * ((60 * hours) + minutes) * 60 * 1000;
// in minutes: 420
}
else if (timezoneType === 'number') {
customTimezoneOffset = timezone * 60 * 1000;
}
}
return new Strftime(_locale, customTimezoneOffset, useUtcBasedDate);
};
strftime.utc = function() {
return new Strftime(_locale, _customTimezoneOffset, true);
};
return strftime;
}
return true;
}
// Default padding is '0' and default length is 2, both are optional.
function pad(n, padding, length) {
// pad(n, <length>)
if (typeof padding === 'number') {
length = padding;
padding = '0';
function padTill2(numberToPad, paddingChar) {
if (paddingChar === '' || numberToPad > 9) {
return numberToPad;
}
if (paddingChar == null) {
paddingChar = '0';
}
return paddingChar + numberToPad;
}
// Defaults handle pad(n) and pad(n, <padding>)
if (padding == null) {
padding = '0';
function padTill3(numberToPad) {
if (numberToPad > 99) {
return numberToPad;
}
if (numberToPad > 9) {
return '0' + numberToPad;
}
return '00' + numberToPad;
}
length = length || 2;
var s = String(n);
// padding may be an empty string, don't loop forever if it is
if (padding) {
while (s.length < length) s = padding + s;
function hours12(hour) {
if (hour === 0) {
return 12;
}
else if (hour > 12) {
return hour - 12;
}
return hour;
}
return s;
}
function hours12(d) {
var hour = d.getHours();
if (hour == 0) hour = 12;
else if (hour > 12) hour -= 12;
return hour;
}
// firstWeekday: 'sunday' or 'monday', default is 'sunday'
//
// Pilfered & ported from Ruby's strftime implementation.
function weekNumber(date, firstWeekday) {
firstWeekday = firstWeekday || 'sunday';
// Get the ordinal suffix for a number: st, nd, rd, or th
function ordinal(n) {
var i = n % 10
, ii = n % 100
;
if ((ii >= 11 && ii <= 13) || i === 0 || i >= 4) {
return 'th';
// This works by shifting the weekday back by one day if we
// are treating Monday as the first day of the week.
var weekday = date.getDay();
if (firstWeekday === 'monday') {
if (weekday === 0) // Sunday
weekday = 6;
else
weekday--;
}
var firstDayOfYear = new Date(date.getFullYear(), 0, 1),
yday = (date - firstDayOfYear) / 86400000,
weekNum = (yday + 7 - weekday) / 7;
return Math.floor(weekNum);
}
switch (i) {
case 1: return 'st';
case 2: return 'nd';
case 3: return 'rd';
}
}
// firstWeekday: 'sunday' or 'monday', default is 'sunday'
//
// Pilfered & ported from Ruby's strftime implementation.
function weekNumber(d, firstWeekday) {
firstWeekday = firstWeekday || 'sunday';
// Get the ordinal suffix for a number: st, nd, rd, or th
function ordinal(number) {
var i = number % 10;
var ii = number % 100;
// This works by shifting the weekday back by one day if we
// are treating Monday as the first day of the week.
var wday = d.getDay();
if (firstWeekday == 'monday') {
if (wday == 0) // Sunday
wday = 6;
else
wday--;
if ((ii >= 11 && ii <= 13) || i === 0 || i >= 4) {
return 'th';
}
switch (i) {
case 1: return 'st';
case 2: return 'nd';
case 3: return 'rd';
}
}
var firstDayOfYear = new Date(d.getFullYear(), 0, 1)
, yday = (d - firstDayOfYear) / 86400000
, weekNum = (yday + 7 - wday) / 7
;
return Math.floor(weekNum);
}
function getTimestampToUtcOffsetFor(date) {
return (date.getTimezoneOffset() || 0) * 60000;
}
}());

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