Skip to content

Commit

Permalink
Merge pull request #1132 from hchiam/dmy-experiment
Browse files Browse the repository at this point in the history
fix(plugins/dates): add dmy option to fix #1131
  • Loading branch information
spencermountain authored Jul 30, 2024
2 parents 18db3da + 8f88fa9 commit b7088bc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugins/dates/builds/compromise-dates.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5110,7 +5110,7 @@
input.month = 'sep';
}
// set it to the beginning of the given unit
let d = spacetime(input, context.timezone, { today: today });
let d = spacetime(input, context.timezone, { today: today, dmy: context.dmy });
Object.defineProperty(this, 'd', {
enumerable: false,
writable: true,
Expand Down
2 changes: 1 addition & 1 deletion plugins/dates/builds/compromise-dates.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/dates/builds/compromise-dates.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/dates/src/api/parse/one/units/Unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Unit {
input.month = 'sep'
}
// set it to the beginning of the given unit
let d = spacetime(input, context.timezone, { today: today })
let d = spacetime(input, context.timezone, { today: today, dmy: context.dmy })
Object.defineProperty(this, 'd', {
enumerable: false,
writable: true,
Expand Down
19 changes: 19 additions & 0 deletions plugins/dates/tests/dmy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'tape'
import nlp from './_lib.js'

test('dmy option falsy', function (t) {
t.equal('March 26', nlp('03/26').dates().format('{month} {date}').text(), 'WITHOUT dmy option')
t.equal('March 26', nlp('03/26').dates({dmy:false}).format('{month} {date}').text(), 'WITHOUT dmy option')
t.equal('March 26', nlp('26/03').dates().format('{month} {date}').text(), 'WITHOUT dmy option')
t.equal('March 26', nlp('26/03').dates({dmy:false}).format('{month} {date}').text(), 'WITHOUT dmy option')
t.equal('March 4', nlp('03/04').dates().format('{month} {date}').text(), 'WITHOUT dmy option')
t.equal('March 4', nlp('03/04').dates({dmy:false}).format('{month} {date}').text(), 'WITHOUT dmy option')

t.end()
})

test('dmy option true', function (t) {
t.equal('April 3', nlp('03/04').dates({dmy: true}).format('{month} {date}').text(), 'WITH dmy option')

t.end()
})

0 comments on commit b7088bc

Please sign in to comment.