Comparing version 0.5.0 to 0.5.1
@@ -6,5 +6,5 @@ { | ||
"keywords": ["strftime", "format", "date", "time"], | ||
"version": "0.4.8", | ||
"version": "0.5.1", | ||
"main": "lib/index.js", | ||
"scripts": ["lib/index.js"] | ||
} |
@@ -27,6 +27,3 @@ /// strftime | ||
namespace.localizedStrftime = localizedStrftime; | ||
namespace.getLocalizedStrftime = function(locale) { | ||
console.log('[strftime] DEPRECATION NOTICE: getLocalizedStrftime is deprecated, use localizedStrftime instead'); | ||
return (namespace.getLocalizedStrftime = localizedStrftime)(locale); | ||
}; | ||
//// | ||
@@ -64,3 +61,3 @@ | ||
// d and locale are optional so check if d is really the locale | ||
if (d && !(d instanceof Date)) { | ||
if (d && !quacksLikeDate(d)) { | ||
locale = d; | ||
@@ -85,6 +82,3 @@ d = undefined; | ||
case 'b': return locale.shortMonths[d.getMonth()]; | ||
case 'C': | ||
var y = String(d.getFullYear()); | ||
return y.slice(0,2); | ||
case 'h': return locale.shortMonths[d.getMonth()]; | ||
case 'C': return pad(Math.floor(d.getFullYear() / 100)); | ||
case 'D': return _strftime(locale.formats.D || '%m/%d/%y', d, locale); | ||
@@ -95,2 +89,3 @@ case 'd': return pad(d.getDate()); | ||
case 'H': return pad(d.getHours()); | ||
case 'h': return locale.shortMonths[d.getMonth()]; | ||
case 'I': return pad(hours12(d)); | ||
@@ -107,4 +102,4 @@ case 'j': | ||
case 'n': return '\n'; | ||
case 'P': return d.getHours() < 12 ? locale.am : locale.pm; | ||
case 'p': return d.getHours() < 12 ? locale.AM : locale.PM; | ||
case 'P': return d.getHours() < 12 ? locale.am : locale.pm; | ||
case 'R': return _strftime(locale.formats.R || '%H:%M', d, locale); | ||
@@ -141,3 +136,3 @@ case 'r': return _strftime(locale.formats.r || '%I:%M:%S %p', d, locale); | ||
var off = d.getTimezoneOffset(); | ||
return (off < 0 ? '+' : '-') + pad(off / 60) + pad(off % 60); | ||
return (off < 0 ? '+' : '-') + pad(Math.abs(off / 60)) + pad(off % 60); | ||
} | ||
@@ -149,5 +144,17 @@ default: return c; | ||
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; | ||
} | ||
} | ||
return true; | ||
} | ||
// Default padding is '0' and default length is 2, both are optional. | ||
function pad(n, padding, length) { | ||
// pad(n, <length>) | ||
@@ -154,0 +161,0 @@ if (typeof padding === 'number') { |
{ | ||
"name": "strftime", | ||
"description": "strftime for JavaScript", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"homepage": "http://samhuri.net/proj/strftime", | ||
@@ -6,0 +6,0 @@ "author": "Sami Samhuri <sami@samhuri.net>", |
strftime | ||
======== | ||
strftime for JavaScript, supports localization. | ||
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. | ||
@@ -18,3 +20,5 @@ | ||
console.log(strftime('%B %d, %y %H:%M:%S')) // => April 28, 2011 18:21:08 | ||
console.log(strftime('%F %T', new Date(1307472705067))) // => 2011-06-07 18:51:45 | ||
If you want to localize it: | ||
@@ -36,2 +40,3 @@ | ||
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 | ||
@@ -45,7 +50,53 @@ And if you don't want to pass a localization object every time you can get a localized `strftime` function like so: | ||
For details just see `man 3 strftime` as the format specifiers are identical. | ||
**NOTE:** `getLocalizedStrftime` is deprecated, use `localizedStrftime` instead. `getLocalizedStrftime` will be removed in 0.5 or 0.6. | ||
Supported Specifiers | ||
==================== | ||
Extensions from Ruby are noted in the following list. | ||
Unsupported specifiers are rendered without the percent sign. | ||
e.g. `%q` becomes `q`. Use `%%` to get a literal `%` sign. | ||
- A: full weekday name | ||
- a: abbreviated weekday name | ||
- B: full month name | ||
- b: abbreviated month name | ||
- C: AD century (year / 100), padded to 2 digits | ||
- D: equivalent to `%m/%d/%y` | ||
- 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` | ||
- H: the hour (24-hour clock), padded to 2 digits (00-23) | ||
- h: the same as %b (abbreviated month name) | ||
- I: the hour (12-hour clock), padded to 2 digits (01-12) | ||
- j: day of the year, padded to 3 digits (001-366) | ||
- k: the hour (24-hour clock), padded with a leading space for single digit values (0-23) | ||
- L: the milliseconds, padded to 3 digits [Ruby extension] | ||
- l: the hour (12-hour clock), padded with a leading space for single digit values (1-12) | ||
- M: the minute, padded to 2 digits (00-59) | ||
- m: the month, padded to 2 digits (01-12) | ||
- n: newline character | ||
- P: "am" or "pm" in lowercase [Ruby extension] | ||
- p: "AM" or "PM" | ||
- R: equivalent to `%H:%M` | ||
- r: equivalent to `%I:%M:%S %p` | ||
- 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: 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` | ||
- 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) | ||
- Y: the year with the century | ||
- y: the year without the century (00-99) | ||
- Z: the time zone name, replaced with an empty string if it is not found | ||
- z: the time zone offset from UTC, with a leading plus sign for UTC and zones east | ||
of UTC and a minus sign for those west of UTC, hours and minutes follow each | ||
padded to 2 digits and with no delimiter between them | ||
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). | ||
Contributors | ||
@@ -63,4 +114,4 @@ ============ | ||
Copyright 2010 - 2012 Sami Samhuri sami@samhuri.net | ||
Copyright 2010 - 2013 Sami Samhuri sami@samhuri.net | ||
MIT (see included [LICENSE](/samsonjs/strftime/blob/master/LICENSE)) |
@@ -0,3 +1,5 @@ | ||
#!/usr/bin/env node | ||
// Based on CoffeeScript by andrewschaaf on github | ||
// | ||
// TODO: | ||
@@ -9,3 +11,3 @@ // - past and future dates, especially < 1900 and > 2100 | ||
var assert = require('assert') | ||
, lib = require('./../lib') | ||
, lib = require('../lib') | ||
@@ -36,6 +38,19 @@ // Tue, 07 Jun 2011 18:51:45 GMT | ||
assert.fn(lib.strftimeUTC) | ||
assert.fn(lib.getLocalizedStrftime) | ||
assert.fn(lib.localizedStrftime) | ||
ok('Exports') | ||
/// time zones | ||
testTimezone('P[DS]T') | ||
if (!process.env.TZ || process.env.TZ == 'America/Vancouver') { | ||
testTimezone('P[DS]T') | ||
assert.format('%C', '01', '01', new Date(100, 0, 1)) | ||
ok('Time zones (' + process.env.TZ + ')') | ||
} | ||
else if (process.env.TZ == 'CET') { | ||
testTimezone('CES?T') | ||
assert.format('%C', '01', '00', new Date(100, 0, 1)) | ||
ok('Time zones (' + process.env.TZ + ')') | ||
} | ||
else { | ||
console.log('(Current timezone has no tests: ' + process.env.TZ + ')') | ||
} | ||
@@ -53,2 +68,3 @@ /// check all formats in GMT, most coverage | ||
assert.format('%H', null, '18') | ||
assert.format('%h', 'Jun') | ||
assert.format('%I', null, '06') | ||
@@ -62,4 +78,4 @@ assert.format('%j', null, '158') | ||
assert.format('%n', '\n') | ||
assert.format('%P', null, 'pm') | ||
assert.format('%p', null, 'PM') | ||
assert.format('%P', null, 'pm') | ||
assert.format('%R', null, '18:51') | ||
@@ -71,9 +87,9 @@ assert.format('%r', null, '06:51:45 PM') | ||
assert.format('%t', '\t') | ||
assert.format('%u', '2') | ||
assert.format('%U', '23') | ||
assert.format('%U', '24', null, new Date(+Time + 5 * 86400000)) | ||
assert.format('%u', '2') | ||
assert.format('%v', '7-Jun-2011') | ||
assert.format('%w', '2') | ||
assert.format('%W', '23') | ||
assert.format('%W', '23', null, new Date(+Time + 5 * 86400000)) | ||
assert.format('%w', '2') | ||
assert.format('%Y', '2011') | ||
@@ -84,3 +100,2 @@ assert.format('%y', '11') | ||
assert.format('%%', '%') // any other char | ||
ok('GMT') | ||
@@ -135,6 +150,5 @@ | ||
assert.format_it('%v', 'it$7-giu-2011') | ||
ok('Localization') | ||
ok('Locales') | ||
/// helpers | ||
@@ -153,23 +167,33 @@ | ||
if (match) { | ||
var hourDiff = Math.floor(Time.getTimezoneOffset() / 60) | ||
, hours = String(18 - hourDiff) | ||
var off = Time.getTimezoneOffset() | ||
, hourOff = off / 60 | ||
, hourDiff = Math.floor(hourOff) | ||
, hours = 18 - hourDiff | ||
, padSpace24 = hours < 10 ? ' ' : '' | ||
, padZero24 = hours < 10 ? '0' : '' | ||
, hour24 = String(hours) | ||
, padSpace12 = (hours % 12) < 10 ? ' ' : '' | ||
, padZero12 = (hours % 12) < 10 ? '0' : '' | ||
, hour12 = String(hours % 12) | ||
, sign = hourDiff < 0 ? '+' : '-' | ||
, minDiff = Time.getTimezoneOffset() - (hourDiff * 60) | ||
, mins = String(51 - minDiff) | ||
, R = hours + ':' + mins | ||
, tz = match[1] | ||
assert.format('%H', hours, '18') | ||
assert.format('%I', hours, '06') | ||
assert.format('%k', hours, '18') | ||
assert.format('%l', hours, ' 6') | ||
, ampm = hour12 == hour24 ? 'AM' : 'PM' | ||
, R = hour24 + ':' + mins | ||
, r = padZero12 + hour12 + ':' + mins + ':45 ' + ampm | ||
, T = R + ':45' | ||
assert.format('%H', padZero24 + hour24, '18') | ||
assert.format('%I', padZero12 + hour12, '06') | ||
assert.format('%k', padSpace24 + hour24, '18') | ||
assert.format('%l', padSpace12 + hour12, ' 6') | ||
assert.format('%M', mins) | ||
assert.format('%p', 'AM', 'PM') | ||
assert.format('%P', 'am', 'pm') | ||
assert.format('%P', ampm.toLowerCase(), 'pm') | ||
assert.format('%p', ampm, 'PM') | ||
assert.format('%R', R, '18:51') | ||
assert.format('%r', R + ':45 AM', '06:51:45 PM') | ||
assert.format('%T', R + ':45', '18:51:45') | ||
assert.format('%r', r, '06:51:45 PM') | ||
assert.format('%T', T, '18:51:45') | ||
assert.format('%Z', tz, 'GMT') | ||
assert.format('%z', sign + '0' + hourDiff + '00', '+0000') | ||
ok(tz) | ||
assert.format('%z', sign + '0' + Math.abs(hourDiff) + '00', '+0000') | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
19008
8
356
114
6