Skip to content

Commit

Permalink
strtotime: Add support oracle dates (fixes #340)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvz committed Apr 5, 2024
1 parent 10fb066 commit c55ff1d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ideas that will be planned and find their way into a release at one point
Released: TBA. [Diff](https://github.com/locutusjs/locutus/compare/v2.0.30...main).

- [x] dx: Add Stale Action
- [x] strtotime: Add support oracle dates (fixes #340)
- [x] bin2hex: Add support for multi-byte characters (fixes #427)
- [x] var_dump: Detect circular references (fixes #305)
- [x] escapeshellarg: Add Windows support (fixes #395)
Expand Down
25 changes: 25 additions & 0 deletions src/php/datetime/strtotime.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,28 @@ const formats = {
},
},

oracledate: {
regex: /^(\d{2})-([A-Z]{3})-(\d{2})$/i,
name: 'd-M-y',
callback(match, day, monthText, year) {
const month = {
JAN: 0,
FEB: 1,
MAR: 2,
APR: 3,
MAY: 4,
JUN: 5,
JUL: 6,
AUG: 7,
SEP: 8,
OCT: 9,
NOV: 10,
DEC: 11,
}[monthText.toUpperCase()]
return this.ymd(2000 + parseInt(year, 10), month, parseInt(day, 10))
},
},

timeLong12: {
regex: RegExp('^' + reHour12 + '[:.]' + reMinute + '[:.]' + reSecondlz + reSpaceOpt + reMeridian, 'i'),
name: 'timelong12',
Expand Down Expand Up @@ -1310,6 +1332,8 @@ module.exports = function strtotime(str, now) {
// returns 5: 1241418600
// example 6: strtotime('2009-05-04 08:30:00 YWT')
// returns 6: 1241454600
// example 7: strtotime('10-JUL-17')
// returns 7: 1499644800

if (now == null) {
now = Math.floor(Date.now() / 1000)
Expand All @@ -1332,6 +1356,7 @@ module.exports = function strtotime(str, now) {
formats.timeShort12,
formats.timeLong12,
formats.mssqltime,
formats.oracledate,
formats.timeShort24,
formats.timeLong24,
formats.iso8601long,
Expand Down
6 changes: 6 additions & 0 deletions test/languages/php/datetime/test-strtotime.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ describe('src/php/datetime/strtotime.js (tested in test/languages/php/datetime/t
expect(result).to.deep.equal(expected)
done()
})
it('should pass example 7', function (done) {
var expected = 1499644800
var result = strtotime('10-JUL-17')
expect(result).to.deep.equal(expected)
done()
})
})

0 comments on commit c55ff1d

Please sign in to comment.