JavaScript
Latest commit 27ac079 Jan 30, 2017 @A---- committed on GitHub Merge pull request #3 from fabianoroberto/master
Fix bower.json
Permalink
Failed to load latest commit information.
dist
src Correct handling of months (usual weird indexing) May 4, 2015
test
.gitignore
Gruntfile.js Adding bitwise check to jshint Apr 28, 2015
LICENSE Initial commit Apr 21, 2015
README.md
bower.json
karma.conf.js Moving source file Apr 22, 2015
package.json Updating to v1.0.1 Apr 6, 2016

README.md

moment-transform

A plugin for Moment.js that allows date transformation from a pattern.

Usage

First, download the plugin by:

  • cloning this repository,
  • use npm or bower,
  • checking the dist/ folder.

Include it in your website/app (after moment if you don't use require).

Then:

var tomorrow = moment().transform('YYYY-MM-+01');
var midnightTonight = moment().transform('YYYY-MM-+01 00:00:00.000');
var breakfirstTimeToday = moment().transform('07:30:00');

// Optional pattern argument
tomorrow = moment().transform('+01/MM/YYYY', 'DD/MM/YYYY');
// Multiple patterns, take the first that fits
midnightTonight = moment().transform('+01/MM/YYYY 00:00:00.000', ['DD/MM/YYYY', 'DD/MM/YYYY HH:mm:ss.SSS']);

// Optional strict argument
tomorrow = moment().transform('+01MMYYYY', 'DD/MM/YYYY', false); // this works
var invalid = moment().transform('+01MMYYYY', 'DD/MM/YYYY', true); // this will return an invalid date.
invalid.isValid(); // false
breakfirstTimeToday = moment().transform('07:30:00', undefined, true); // with default patterns

Options

transform() takes up to three arguments:

  • value: value to be checked against the pattern,
  • patterns (optional): a string or an array of strings. Check format() documentation for syntax. Default value is ['YYYY-MM-DD HH:mm:ss.SSS', 'YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD', 'HH:mm:ss.SSS', 'HH:mm:ss'].
  • strict (optional): non-alphabetic characters in patterns are not mandatory when not strict. Default is false.

Contributing

Fork the repository and do a npm install.

You can check your code is correct by doing a grunt test.

When you're done, do a grunt build.