パッケージの詳細

moment-strftime

benjaminoakes13.2kMIT0.5.0

moment-strftime adds strftime to Moment.js

moment, date, strftime

readme

moment-strftime

Build Status Flattr this git repo

Moment.js is a great, lightweight date-manipulation library. It also has a very approachable date format syntax that would be familiar to most people who have ever had to fill out a form (e.g., guess what 'YYYY-MM-DD' means).

Most programmers however, are familiar with other date formatting syntax. The Unix-style strftime is commonly found in many languages' standard libraries. Unfortunately, it is still absent in JavaScript.

Moment.js helps with a lot of the pain associated with Date handling in JavaScript, but it doesn't handle strftime (nor will it, it seems). If you are working in a language that does have strftime, it seems awkward to have to use another format when using JavaScript (especially if you're trying to keep formats consistent between languages).

That's unfortunate. There are too many (abandoned, buggy) solutions for date handling in JavaScript. Moment.js has the most steam behind it because of all the other features it has going for it.

But... if Moment.js just had strftime and friends, why would you need anything else? Enter moment-strftime.

Installation

Browser

It's preferred that you use Bower, but you can also download the raw JavaScript.

Node.js

moment-strftime is available as a Node.js package. The JavaScript itself should work as a CommonJS module, but it has only been tested in Node.js.

npm install moment-strftime

Usage

moment-strftime is a tiny plugin for Moment.js that adds a strftime method. It's simple:

moment().strftime("%m/%d/%y %I:%M %p %Z"); // => '01/17/12 08:54 PM EST'

In Node.js:

// Gets you everything in Moment.js too
var moment = require('moment-strftime');
moment().strftime("%m/%d/%y %I:%M %p %Z"); // => '01/17/12 08:54 PM EST'

Known Issues

Compatibility: stable Chrome, stable Firefox, stable Safari, IE9+

I've only developed moment-strftime as far as I need it right now, rather than implementing features I don't need yet. I've noticed that implementing "unused" features often leads to bugs, so the plan is to implement on an as-needed basis.

If you run into an issue or unimplemented feature that you need, please open an issue or (preferably) make a pull request.

Contributing

To get up and running:

docker-compose build
docker-compose run test

Resources

License

MIT (see LICENSE)

更新履歴

moment-strftime (0.5.0) stable; urgency=low

  • Jamie Lubiner: Add support for lowercase meridian indicator (%P for am/pm) (Closes: #31)

    -- Benjamin Oakes hello@benjaminoakes.com Wed, 29 Aug 2018 11:55:00 +0000

moment-strftime (0.4.1) stable; urgency=low

  • Reduce maintenance overhead; no functional changes.

    -- Benjamin Oakes hello@benjaminoakes.com Fri, 24 Aug 2018 13:20:00 +0000

moment-strftime (0.4.0) stable; urgency=low

  • Serhiy Yefremenko: Support for unpadded tokens like %-d (Closes: #30)

    -- Benjamin Oakes hello@benjaminoakes.com Fri, 10 Aug 2018 12:40:00 +0000

moment-strftime (0.3.2) stable; urgency=low

  • Change minimum version of moment.js to mitigate DoS (Closes: #24, #29)

    -- Benjamin Oakes hello@benjaminoakes.com Fri, 27 Apr 2018 14:30:00 +0000

moment-strftime (0.3.1) stable; urgency=low

  • Gilmore Davidson: More accurate replacement of strftime tokens (Closes: #25, #28)

    -- Benjamin Oakes hello@benjaminoakes.com Fri, 27 Apr 2018 14:00:00 +0000

moment-strftime (0.3.0) stable; urgency=low

  • Sambhav Kothari: Add support for locale-preferred date and time representation (Closes: #26, #27)

    -- Benjamin Oakes hello@benjaminoakes.com Wed, 21 Mar 2018 14:00:00 +0000

moment-strftime (0.2.3) stable; urgency=low

  • Ziv Perry: Add support for fractional seconds (Closes: #23)

    -- Benjamin Oakes hello@benjaminoakes.com Mon, 11 Sep 2017 15:30:00 +0000

moment-strftime (0.2.2) stable; urgency=low

  • Julian Scheid: Relax moment dependency constraint (Closes: #22)

    -- Benjamin Oakes hello@benjaminoakes.com Tue, 14 Jun 2017 20:00:00 +0000

moment-strftime (0.2.1) stable; urgency=low

  • Jed Fox: Fix webpack critical dependency warning (Closes: #20, #21)

    -- Benjamin Oakes hello@benjaminoakes.com Tue, 28 Feb 2017 10:20:00 -6000

moment-strftime (0.2.0) stable; urgency=low

  • Start official support for Node 4, 5, 6, and 7.
  • Add Docker container for development.
  • Remove "build" directory and included minified JavaScript.
  • Martin Hradil: Update moment dependency to allow any 2.x version. (Closes: #19)
  • Paweł Sierszeń, David Rojo Gonzalez: Fix formatting of normal non-parameterized text (Closes: #16, #17, #18)

    -- Benjamin Oakes hello@benjaminoakes.com Wed, 26 Oct 2016 10:00:00 -5000

moment-strftime (0.1.5) stable; urgency=low

  • Martin Hradil: Regenerate build for bower. (Closes: #15)

    -- Benjamin Oakes hello@benjaminoakes.com Wed, 22 Sep 2015 02:42:00 +0000

moment-strftime (0.1.4) stable; urgency=low

  • Martin Hradil: Add "%k" (hour of day, no leading zero, 24-hour clock), "%l" (hour of day, no leading zero, 12-hour clock), "%u" (numeric day of week with Sunday as 7), and "%W" (week number with leading zero) (Closes: #14)
  • Martin Hradil: Specify that "%Z" gives "UTC" for a moment.utc time (Closes: #14)

    -- Benjamin Oakes hello@benjaminoakes.com Wed, 9 Jul 2015 03:20:00 +0000

moment-strftime (0.1.3) stable; urgency=low

  • Started official support for stable node.js, node.js v0.10.x, node.js v0.12.x, and stable io.js
  • Brandon Pittman: Add "%F" replacement, common shortcut for the date command in Unix (Closes: #6)
  • Pierre Rudloff: Add Bower package (Closes: #7)
  • Pierre Rudloff: Update moment dependency (Closes: #11)
  • Nicolas: Add "%e" replacement, day of the month without leading zero (Closes: #12)

    -- Benjamin Oakes hello@benjaminoakes.com Wed, 9 Jul 2015 03:20:00 +0000

moment-strftime (0.1.2) stable; urgency=low

moment-strftime (0.1.1) stable; urgency=low

moment-strftime (0.1.0) stable; urgency=low