Giter Club home page Giter Club logo

node-dateformat's Introduction

dateformat

A node.js package for Steven Levithan's excellent dateFormat() function.

Modifications

  • Removed the Date.prototype.format method. Sorry folks, but extending native prototypes is for suckers.
  • Added a module.exports = dateFormat; statement at the bottom
  • Added the placeholder N to get the ISO 8601 numeric representation of the day of the week

Installation

$ npm install dateformat
$ dateformat --help

Usage

As taken from Steven's post, modified to match the Modifications listed above:

import dateFormat, { masks } from "dateformat";
const now = new Date();

// Basic usage
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
// Saturday, June 9th, 2007, 5:46:21 PM

// You can use one of several named masks
dateFormat(now, "isoDateTime");
// 2007-06-09T17:46:21

// ...Or add your own
masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
dateFormat(now, "hammerTime");
// 17:46! Can't touch this!

// You can also provide the date as a string
dateFormat("Jun 9 2007", "fullDate");
// Saturday, June 9, 2007

// Note that if you don't include the mask argument,
// dateFormat.masks.default is used
dateFormat(now);
// Sat Jun 09 2007 17:46:21

// And if you don't include the date argument,
// the current date and time is used
dateFormat();
// Sat Jun 09 2007 17:46:22

// You can also skip the date argument (as long as your mask doesn't
// contain any numbers), in which case the current date/time is used
dateFormat("longTime");
// 5:46:22 PM EST

// And finally, you can convert local time to UTC time. Simply pass in
// true as an additional argument (no argument skipping allowed in this case):
dateFormat(now, "longTime", true);
// 10:46:21 PM UTC

// ...Or add the prefix "UTC:" or "GMT:" to your mask.
dateFormat(now, "UTC:h:MM:ss TT Z");
// 10:46:21 PM UTC

// You can also get the ISO 8601 week of the year:
dateFormat(now, "W");
// 42

// and also get the ISO 8601 numeric representation of the day of the week:
dateFormat(now, "N");
// 6

Mask options

Mask Description
d Day of the month as digits; no leading zero for single-digit days.
dd Day of the month as digits; leading zero for single-digit days.
ddd Day of the week as a three-letter abbreviation.
DDD "Ysd", "Tdy" or "Tmw" if date lies within these three days. Else fall back to ddd.
dddd Day of the week as its full name.
DDDD "Yesterday", "Today" or "Tomorrow" if date lies within these three days. Else fall back to dddd.
m Month as digits; no leading zero for single-digit months.
mm Month as digits; leading zero for single-digit months.
mmm Month as a three-letter abbreviation.
mmmm Month as its full name.
yy Year as last two digits; leading zero for years less than 10.
yyyy Year represented by four digits.
h Hours; no leading zero for single-digit hours (12-hour clock).
hh Hours; leading zero for single-digit hours (12-hour clock).
H Hours; no leading zero for single-digit hours (24-hour clock).
HH Hours; leading zero for single-digit hours (24-hour clock).
M Minutes; no leading zero for single-digit minutes.
MM Minutes; leading zero for single-digit minutes.
N ISO 8601 numeric representation of the day of the week.
o GMT/UTC timezone offset, e.g. -0500 or +0230.
p GMT/UTC timezone offset, e.g. -05:00 or +02:30.
s Seconds; no leading zero for single-digit seconds.
ss Seconds; leading zero for single-digit seconds.
S The date's ordinal suffix (st, nd, rd, or th). Works well with d.
l Milliseconds; gives 3 digits.
L Milliseconds; gives 2 digits.
t Lowercase, single-character time marker string: a or p.
tt Lowercase, two-character time marker string: am or pm.
T Uppercase, single-character time marker string: A or P.
TT Uppercase, two-character time marker string: AM or PM.
W ISO 8601 week number of the year, e.g. 4, 42
WW ISO 8601 week number of the year, leading zero for single-digit, e.g. 04, 42
Z US timezone abbreviation, e.g. EST or MDT. For non-US timezones, the GMT/UTC offset is returned, e.g. GMT-0500
'...', "..." Literal character sequence. Surrounding quotes are removed.
UTC: Must be the first four characters of the mask. Converts the date from local time to UTC/GMT/Zulu time before applying the mask. The "UTC:" prefix is removed.

Named Formats

Name Mask Example
default ddd mmm dd yyyy HH:MM:ss Sat Jun 09 2007 17:46:21
shortDate m/d/yy 6/9/07
paddedShortDate mm/dd/yyyy 06/09/2007
mediumDate mmm d, yyyy Jun 9, 2007
longDate mmmm d, yyyy June 9, 2007
fullDate dddd, mmmm d, yyyy Saturday, June 9, 2007
shortTime h:MM TT 5:46 PM
mediumTime h:MM:ss TT 5:46:21 PM
longTime h:MM:ss TT Z 5:46:21 PM EST
isoDate yyyy-mm-dd 2007-06-09
isoTime HH:MM:ss 17:46:21
isoDateTime yyyy-mm-dd'T'HH:MM:sso 2007-06-09T17:46:21+0700
isoUtcDateTime UTC:yyyy-mm-dd'T'HH:MM:ss'Z' 2007-06-09T22:46:21Z

Localization

Day names, month names and the AM/PM indicators can be localized by passing an object with the necessary strings. For example:

import { i18n } from "dateformat";

i18n.dayNames = [
  "Sun",
  "Mon",
  "Tue",
  "Wed",
  "Thu",
  "Fri",
  "Sat",
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
];

i18n.monthNames = [
  "Jan",
  "Feb",
  "Mar",
  "Apr",
  "May",
  "Jun",
  "Jul",
  "Aug",
  "Sep",
  "Oct",
  "Nov",
  "Dec",
  "January",
  "February",
  "March",
  "April",
  "May",
  "June",
  "July",
  "August",
  "September",
  "October",
  "November",
  "December",
];

i18n.timeNames = ["a", "p", "am", "pm", "A", "P", "AM", "PM"];

Notice that only one language is supported at a time and all strings must be present in the new value.

Breaking change in 2.1.0

  • 2.1.0 was published with a breaking change, for those using localized strings.
  • 2.2.0 has been published without the change, to keep packages refering to ^2.0.0 to continue working. This is now branch v2_2.
  • 3.0.* contains the localized AM/PM change.

License

(c) 2007-2009 Steven Levithan stevenlevithan.com, MIT license.

node-dateformat's People

Contributors

chase-manning avatar cliffano avatar clintandrewhall avatar coffbr01 avatar ctavan avatar doowb avatar fboes avatar felixge avatar felixonmars avatar fpintos avatar hooriza avatar jamiebuilds avatar jamielinux avatar jerryjj avatar jimmywarting avatar jonmooring avatar jonschlinkert avatar justin-john avatar lbdremy avatar michaelsanford avatar mikegreiling avatar milohax avatar nestedscope avatar nschonni avatar pdehaan avatar robinj avatar samt avatar sinewalker avatar smithalexk avatar talhaawan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-dateformat's Issues

Add "tick" option to provide continuous output

I am interested in having a ticking clock command line utility, to be able to pipe it into other things.

Would you be interested in having it added to node-dateformat? If so, I am willing to contribute a pull request. Otherwise, I'll probably create a new package based on node-dateformat.

I was thinking along the lines of

dateformat "HH:MM:ss" -t 
dateformat "HH:MM:ss" -t 5s
dateformat "HH:MM:ss" -t 1m

to tick every second, 5 seconds and minute.

isoUtcDateTime doesn't even come close ...

TypeScript:

var date: Date = new Date();
var d: string = dateFormat(date, "isoUtcDateTime");

Yields ... ==> "07/28/2016 16:13:39"

instead of the "2010-12-08T16:42:48Z" type of format ...

Provide PDF date format

For PDF metadata fields CreationDate and ModDate

Format: (D:YYYYMMDDHHmmSSOHH'mm')

where

YYYY is the year
MM is the month
DD is the day (01-31)
HH is the hour (00-23)
mm is the minute (00-59)
SS is the second (00-59)
O is the relationship of local time to Universal Time (UT), denoted by one of the characters +, -, or Z
HH followed by ' is the absolute value of the offset from UT in hours (00-23)
mm followed by ' is the absolute value of the offset from UT in minutes (00-59)

Invalid parsed date

Hi there, i tried dateformat via browser and locally in a js script, and the basic test was to instantiate a new date (1st Feb 2018). After providing the parameters as required, i get 1st Mar 2018. The month label is wrong.

capture
Snapshot as attachment.

Issue on passing normal text to dateFormat function

As per README.md description the following code should work:

// ...Or add your own
dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
dateFormat(now, "hammerTime");
// 17:46! Can't touch this!

But, as I have seen in my app, it does not. So I figured it out that I have to pass the desired text nested in the same type of quote (single ' or double "), with backward slashes, as the one the nests the format it self.

Example given (double quotes):

// Now this works
dateFormat.masks.hammerTime = "HH:MM! \"Can't touch this!\"";
dateFormat(now, "hammerTime");
// 17:46! Can't touch this!

So, I have no idea if I'm doing something wrong, but if this is true a real issue that I see is that would be impossible to pass the word can't as normal text when using single quotes...

isoDateTime should include timezone (or UTC)

Right now, using dateFormat isoDateTime produces:

 Date: 2014-06-27T00:37:07

Which is confusing because it applied my local time zone (UTC +02:00) but also left out any timezone indication. This is imho invalid ISO. It should use UTC and include a Z at the end, or include the indication for the timezone used.

Incorrectly subtracting days when formatting from yyyy-mm-dd

var dateFormat = require('dateformat');

var d = '1994-03-08';
console.log(dateFormat(d, 'yyyy-mm-dd'));

^This incorrectly prints '1994-03-07'

d = '1994-03-11'
console.log(dateFormat(d, 'yyyy-mm-dd'));

And ^this incorrectly prints '1994-03-10'

d = '1994-03-8';
console.log(dateFormat(d, 'yyyy-mm-dd'));

But ^this correctly prints '1994-03-08'

[Fork & Pull request]: adding localisation information to date formatter

I've come across this lib and observed that all days/months strings are in English. I would like to propose extending this lib to accommodate strings in other languages. If the repo maintainers agree to this change, I'd be happy to fork the repo and implement the change for a pull consideration.

isodatetime issue

Hello,

I am converting date '31 Mar 2017' to '2017-03-31T00:00:00'. I found solution as per your documentation: dateFormat(now, "isoDateTime");
so when i am using this :dateFormat('31 Mar 2017', "isoDateTime");
it is giving me output like:2017-03-31T00:00:00+0530
but i don't want +0530 part with datetime. please provide me the solution asap.

Not able to install dateFormat - Cannot convert undefined or null to object

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs',
1 verbose cli '/usr/bin/npm',
1 verbose cli 'install',
1 verbose cli 'dateFormat',
1 verbose cli '--save' ]
2 info using [email protected]
3 info using [email protected]
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData dateFormat
8 silly fetchNamedPackageData dateFormat
9 silly mapToRegistry name dateFormat
10 silly mapToRegistry using default registry
11 silly mapToRegistry registry https://registry.npmjs.org/
12 silly mapToRegistry data Result {
12 silly mapToRegistry raw: 'dateFormat',
12 silly mapToRegistry scope: null,
12 silly mapToRegistry escapedName: 'dateFormat',
12 silly mapToRegistry name: 'dateFormat',
12 silly mapToRegistry rawSpec: '',
12 silly mapToRegistry spec: 'latest',
12 silly mapToRegistry type: 'tag' }
13 silly mapToRegistry uri https://registry.npmjs.org/dateFormat
14 verbose request uri https://registry.npmjs.org/dateFormat
15 verbose request no auth needed
16 info attempt registry request try #1 at 10:05:55 PM
17 verbose request id f78e4ab09abb4f13
18 verbose etag W/"57d11e71-189"
19 verbose lastModified Thu, 08 Sep 2016 08:16:49 GMT
20 http request GET https://registry.npmjs.org/dateFormat
21 http 304 https://registry.npmjs.org/dateFormat
22 verbose headers { date: 'Tue, 02 May 2017 16:35:56 GMT',
22 verbose headers via: '1.1 varnish',
22 verbose headers 'cache-control': 'max-age=300',
22 verbose headers etag: 'W/"57d11e71-189"',
22 verbose headers age: '147',
22 verbose headers connection: 'keep-alive',
22 verbose headers 'x-served-by': 'cache-sin18025-SIN',
22 verbose headers 'x-cache': 'HIT',
22 verbose headers 'x-cache-hits': '1',
22 verbose headers 'x-timer': 'S1493742957.830855,VS0,VE0',
22 verbose headers vary: 'Accept-Encoding' }
23 silly get cb [ 304,
23 silly get { date: 'Tue, 02 May 2017 16:35:56 GMT',
23 silly get via: '1.1 varnish',
23 silly get 'cache-control': 'max-age=300',
23 silly get etag: 'W/"57d11e71-189"',
23 silly get age: '147',
23 silly get connection: 'keep-alive',
23 silly get 'x-served-by': 'cache-sin18025-SIN',
23 silly get 'x-cache': 'HIT',
23 silly get 'x-cache-hits': '1',
23 silly get 'x-timer': 'S1493742957.830855,VS0,VE0',
23 silly get vary: 'Accept-Encoding' } ]
24 verbose etag https://registry.npmjs.org/dateFormat from cache
25 verbose get saving dateFormat to /home/rajayasw/.npm/registry.npmjs.org/dateFormat/.cache.json
26 verbose correctMkdir /home/rajayasw/.npm correctMkdir not in flight; initializing
27 verbose stack TypeError: Cannot convert undefined or null to object
27 verbose stack at Function.keys ()
27 verbose stack at pickVersionFromRegistryDocument (/usr/lib/node_modules/npm/lib/fetch-package-metadata.js:126:29)
27 verbose stack at /usr/lib/node_modules/npm/node_modules/iferr/index.js:13:50
27 verbose stack at /usr/lib/node_modules/npm/lib/utils/pulse-till-done.js:20:8
27 verbose stack at saved (/usr/lib/node_modules/npm/lib/cache/caching-client.js:174:7)
27 verbose stack at /usr/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:261:18
27 verbose stack at FSReqWrap.oncomplete (fs.js:114:15)
28 verbose cwd /mnt/d/mongo-twitter
29 error Linux 4.4.0-43-Microsoft
30 error argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "dateFormat" "--save"
31 error node v7.9.0
32 error npm v4.2.0
33 error Cannot convert undefined or null to object
34 error If you need help, you may report this error at:
34 error https://github.com/npm/npm/issues
35 verbose exit [ 1, true ]

TypeError: Invalid date (version 1.0.12) on Google Cloud Platform

I'm using dateformat for a custom node module deployed on Google Cloud Platform.

code similar to:
dateFormat(new Date().getTime(), "dddd, mmmm dS yyyy, h:MM TT");
And getting a "TypeError: Invalid date) error. Here's the trace:

trying to do a dateFormat for timestamp: 1481054683108
events.js:160
      throw er; // Unhandled 'error' event
      ^

TypeError: Invalid date
    at TypeError (native)
    at /opt/bitnami/apps/myapp/node_modules/dateformat/lib/dateformat.js:39:17

I believe the issue has something to do with the timestamp. Because when I run outside of GCP on my local machine I also get the TypeError.

dateformat 1481054683108, "dddd, mmmm dS yyyy, h:MM TT"

but that timestamp seems okay (it's off from now but that's a different issue). Any other reason why I would be seeing this error? Running the same code locally works just fine (same versions of dateformat requirement), but the timestamp is a different value than what is created on the server...

Two digit milliseconds L sometimes returns three digits

I have a dateformat string that uses L, which should return milliseconds with 2 digits. The full dateformat string is yyyymmddHHMMssL, which should generate a 16 digit string that is then followed by other data - it's used for a filename generator.

I have a unit test doing a sanity check on this, which checks the presence of 16 digits using regexp.

Once in a blue moon this test fails because the resulting date format string contains 17 digits. The resulting string this morning was 20180727084011100.

Is it possible that L gave 100 here because it ended with 00?

Either way, the expected behaviour is that L should always return two digits as the spec says. I'll change to use l for now.

dateformat library throws uncaught error when invalid date string is passed in

Had a process exit unexpectedly today due to a malformed date string.

I understand why dateformat choose this API ( throwing an error ), because it's logical. What was not so nice, was having the process exit.

If anyone else hits this issue and is looking for a solution, you can simply create a wrapper method for dateformat with try / catch that returns a string ( instead of throwing an error ).

var df = require('dateformat');

var safeDf = function safeDf (str) {
  var res = '';
  try  {
    res = df(str);
  } catch (err) {
    res = "NaN";
  }
  return res;
};

Format L wrong

I think "L" should be hundredth seconds.

The calcutaion is wrong:
L: pad(L > 99 ? Math.round(L / 10) : L),
10 milliseconds => 10 hundredth
99 milliseconds => 99 hundredth
100 milliseconds => 10 hundredth

correct:
L: pad(Math.round(L / 10)),
10 milliseconds => 1 hundredth
99 milliseconds => 10 hundredth
100 milliseconds => 10 hundredth

publish a non-prerelease version of dateformat to npm

Hey there!

npm 2.0.0 is currently scheduled to drop this Thursday. It depends on node-semver@4, which has a bunch of tweaks to how node-semver deals with version ranges. In particular, ranges (including the ~ and ^ operators) no longer match prerelease versions, which in semver terms means versions including -.

As dateformat has never published a non-prerelease version (in semver terms), this means that any package that is depending on dateformat but isn't explicitly pinning the dependency version will no longer be able to successfully install. The fix is pretty simple – just publish [email protected].

I'm sorry about the short notice! I feel pretty good about the tweaks we've made to semver, but at this point it's impossible to make changes without being a little disruptive.

Will there be a typings file?

I'm using your component, but I would like to use it a little bit more typesave.
I'm using typescript: Is there some typedefintion out there for dateformat (official/inofficial) or are you planning to provide one .d.ts-File?

Thanks!

consider moving cli to different lib

I love using this, but I just realized that it's using meow, and I'm guessing that a good percentage of users like myself probably aren't using the CLI, but the dependency tree for it is absurdly massive. Especially considering this would have zero deps without it.

meow has 48 dependencies in total, this is its flattened dependency tree (along with the number of times each module appears in the tree):

{
  'trim-newlines': 1,
  'redent': 1,
  'strip-indent': 1,
  'get-stdin': 1,
  'indent-string': 1,
  'repeating': 1,
  'is-finite': 1,
  'number-is-nan': 1,
  'read-pkg-up': 1,
  'read-pkg': 1,
  'path-type': 1,
  'pinkie-promise': 4,
  'pinkie': 4,
  'pify': 2,
  'graceful-fs': 2,
  'normalize-package-data': 1,
  'load-json-file': 1,
  'strip-bom': 1,
  'is-utf8': 1,
  'parse-json': 1,
  'error-ex': 1,
  'find-up': 1,
  'path-exists': 1,
  'object-assign': 1,
  'validate-npm-package-license': 1,
  'spdx-expression-parse': 1,
  'spdx-license-ids': 2,
  'spdx-exceptions': 1,
  'spdx-correct': 1,
  'semver': 1,
  'is-builtin-module': 1,
  'builtin-modules': 1,
  'hosted-git-info': 1,
  'minimist': 1,
  'loud-rejection': 1,
  'camelcase-keys': 1,
  'map-obj': 1,
  'camelcase': 1
}

Week calculation is wrong ... includes decimals

It look like using 'W' format returns also decimals ... ex:

var df = require('dateformat');
console.log(df('W'));

will return 30.351190476190474 instead of 30

I'm running on Win 7/x64 with node 0.10.15/x64

get a wrong minute!

Show info:

dateformat('2016-01-12', 'mm-dd-yyyy hh:mm:ss')
'01-12-2016 08:01:00'
dateformat(new Date(), 'yyyy年mm月dd日 HH:mm')
'2017年08月15日 14:08'
new Date()
2017-08-15T06:00:47.027Z

null is converted to current date

is this normal that null var is converted to current date?
if yes is there a option to disable such behaviour

result.data= dateFormat(data, "yyyy-mm-dd");

Supporting more digits in MS

l | Milliseconds; gives 3 digits.

Do we have support in having more digits, like for 6 digits? We have 2 digits L and 3 digits l support today.

Tests are dependent on local timezone settings

I was running the tests locally by request of someone in the #Node.js IRC channel and noticed that I got a different set of test failures depending on the timezone settings of my computer.

With timezone set to GMT (my normal timezone):

  1) dateformat([now], [mask]) should format `longTime` mask:
     AssertionError: '1:19:44 PM GMT' === '1:19:44 PM UTC'
      at Context.<anonymous> (/Users/lenny/dev/node-dateformat/test/test_formats.js:64:14)
      at Test.Runnable.run (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runnable.js:217:15)
      at Runner.runTest (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:373:10)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:298:14)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:246:23)
      at Immediate._onImmediate (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:368:17)

  2) dateformat([now], [mask]) should format `expiresHeaderFormat` mask:
     AssertionError: 'Wed, 26 Nov 2014 13:19:44 GMT' === 'Wed, 26 Nov 2014 13:19:44 UTC'
      at Context.<anonymous> (/Users/lenny/dev/node-dateformat/test/test_formats.js:64:14)
      at Test.Runnable.run (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runnable.js:217:15)
      at Runner.runTest (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:373:10)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:298:14)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:246:23)
      at Immediate._onImmediate (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:368:17)

With my timezone set to EST:

  1) dayOfWeek should correctly format the timezone part:
     AssertionError: '7' === '1'
      at Context.<anonymous> (/Users/lenny/dev/node-dateformat/test/test_dayofweek.js:11:14)
      at Test.Runnable.run (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runnable.js:217:15)
      at Runner.runTest (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:373:10)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:298:14)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:246:23)
      at Immediate._onImmediate (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:368:17)

  2) dateformat([now], [mask]) should format `longTime` mask:
     AssertionError: '1:19:44 PM EST' === '1:19:44 PM GMT--500'
      at Context.<anonymous> (/Users/lenny/dev/node-dateformat/test/test_formats.js:64:14)
      at Test.Runnable.run (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runnable.js:217:15)
      at Runner.runTest (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:373:10)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:298:14)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:246:23)
      at Immediate._onImmediate (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:368:17)

  3) dateformat([now], [mask]) should format `isoDateTime` mask:
     AssertionError: '2014-11-26T13:19:44-0500' === '2014-11-26T13:19:44--500'
      at Context.<anonymous> (/Users/lenny/dev/node-dateformat/test/test_formats.js:64:14)
      at Test.Runnable.run (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runnable.js:217:15)
      at Runner.runTest (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:373:10)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:298:14)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:246:23)
      at Immediate._onImmediate (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:368:17)

  4) dateformat([now], [mask]) should format `expiresHeaderFormat` mask:
     AssertionError: 'Wed, 26 Nov 2014 13:19:44 EST' === 'Wed, 26 Nov 2014 13:19:44 GMT--500'
      at Context.<anonymous> (/Users/lenny/dev/node-dateformat/test/test_formats.js:64:14)
      at Test.Runnable.run (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runnable.js:217:15)
      at Runner.runTest (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:373:10)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:298:14)
      at /Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:246:23)
      at Immediate._onImmediate (/Users/lenny/dev/node-dateformat/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:368:17)

Stick version of get-stdin

A new major version of get-stdin has been published yesterday (v5.0.0).
It now uses native promises. So, it does not support Node 0.10.x anymore.

Would it be possible to stick the dependency at ^0.4.1?

Getting Wrong out-put

Input:
var nowDateYMD = dateformat('2016-01-12', 'mm-dd-yyyy');
Output Date:
01-11-2016 // giving wrong date, showing one day less

Kindly do need full.

Thanks.

minus some days in current date

How to minus some days(integer) in current date?

for example:
Current date = 10/25/2017 (MM/DD/YYYY),
i want to minus 4 days from current date.
(expect this date 10/21/2017)

Please pad years before the year 1000

Currently when attempting to format the year of any year before the year 1000, you end up with a less than ideal looking string.

IE: 0012/06/24 will become 12/06/24, which does not fit into a html date input field. Can you please pad zeroes out for any year before the 1000 to avoid this issue?

Passing date through Date ruins Timezone

I'm using a Timezone binding for Node that allows for Timezone creation:

https://github.com/TooTallNate/node-time

Unfortunately, the line:

// Passing date through Date applies Date.parse, if necessary
date = date ? new Date(date) : new Date;

resets this Date implementation to the local timezone, or that of the server. I don't see a problem with:

// Passing date through Date applies Date.parse, if necessary
if(!date || !(date instanceof Date)) {
  date = date ? new Date(date) : new Date;
}

... does anyone disagree?

Uncaught TypeError: Invalid date

I am using this package with webpack on browser side.

I am using it like this.

var formatDate = require('dateformat'); 

but I am getting this error. "Uncaught TypeError: Invalid date"

notice that, I am getting this error even when not use.

I think this problem about this line

Timezone conversion and custom named formats

So far this library is working great for us, two improvements I'd like to suggest:

  1. Allow changing timezone - We have one date that we need to display formatted in couple of timezones, would be great if that could be achieved directly with this library

  2. Custom named formats - Would be great if you could specify your own named formats. For example the fullDate is great, but we need same just without the commas. Sure we can achieve it otherwise, but specifying our own custom named formats would be a big bonus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.