Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch for helper-date 0.2.3 compatibility #180

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions helpers/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ const factory = () => {
return function (str, pattern) {
// always use the Handlebars-generated options object
let options = arguments[arguments.length - 1];
if (arguments.length < 3) {
pattern = null;
}
if (arguments.length < 2) {
str = null;
}

// Ideally we'd check how many args were passed and set `str` and `pattern` to
// null if they weren't explicitly provided. However, doing so could break
// backwards compatibility since we previously depended on [email protected].

// if no args are passed, return a formatted date
if (str === null && pattern === null) {
/* eslint no-eq-null: ["off"] */
if (str == null && pattern == null) {
moment.locale('en');
return moment().format('MMMM DD, YYYY');
}
Expand Down
22 changes: 22 additions & 0 deletions spec/helpers/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Lab = require('lab'),
describe = lab.experiment,
it = lab.it,
testRunner = require('../spec-helpers').testRunner;
const moment = require('moment');

describe('moment helper', function () {
const runTestCases = testRunner({});
Expand All @@ -13,7 +14,28 @@ describe('moment helper', function () {
{
input: `{{moment "1 year ago" "YYYY"}}`,
output: `${now.getFullYear() - 1}`,
}
], done);
});

it('is backwards compatible with helper-date 0.2.3 null-argument behavior', (done) => {
runTestCases([
{
input: `{{moment format="YYYY"}}`,
output: moment().format('YYYY'),
},
{
input: `{{moment null null}}`,
output: moment().format('MMMM DD, YYYY'),
},
{
input: `{{moment undefined undefined}}`,
output: moment().format('MMMM DD, YYYY'),
},
{
input: `{{moment "now" format="YYYY"}}`,
output: `Invalid date`,
}
], done);
});

Expand Down