Skip to content

Commit

Permalink
fix: STRF-9936 Replaced outdated date.js with chrono (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
jairo-bc authored Aug 25, 2023
1 parent 5b59eb3 commit 9675357
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions helpers/moment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const utils = require('./3p/utils');
const date = require('date.js');
const chrono = require('chrono-node');

// suppress error messages that are not actionable
const moment = require('moment');
Expand Down Expand Up @@ -40,7 +40,7 @@ const factory = () => {
// so instead of doing magic we'll just ask the user to tell
// us if the args should be passed to date.js or moment.
if (typeof str === 'string' && typeof pattern === 'string') {
return moment(date(str)).format(pattern);
return moment(chrono.parseDate(str)).format(pattern);
}

// If handlebars, expose moment methods as hash properties
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"homepage": "https://github.com/bigcommerce/paper-handlebars",
"dependencies": {
"@bigcommerce/handlebars-v4": "4.7.6",
"date.js": "^0.3.3",
"chrono-node": "^2.6.5",
"handlebars": "3.0.8",
"he": "^1.2.0",
"moment": "^2.29.4",
Expand Down
20 changes: 20 additions & 0 deletions spec/helpers/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ describe('moment helper', function () {
{
input: `{{moment "1 year ago" "YYYY"}}`,
output: `${now.getFullYear() - 1}`,
},
{
input: `{{moment "2 days ago" "YYYY"}}`,
output: `${now.getFullYear()}`,
},
{
input: `{{moment '2022-06-29' 'DD/MM/YYYY'}}`,
output: '29/06/2022',
},
{
input: `{{moment '2022-06-30' 'DD/MM/YYYY'}}`,
output: '30/06/2022',
},
{
input: `{{moment '2022-07-29' 'DD/MM/YYYY'}}`,
output: '29/07/2022',
},
{
input: `{{moment '2022-07-30' 'DD/MM/YYYY'}}`,
output: '30/07/2022',
}
], done);
});
Expand Down

0 comments on commit 9675357

Please sign in to comment.