From c55ff1d8629a126511f7f11f3bbcd69ba0f6342d Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Fri, 5 Apr 2024 17:21:05 +0200 Subject: [PATCH] strtotime: Add support oracle dates (fixes #340) --- CHANGELOG.md | 1 + src/php/datetime/strtotime.js | 25 +++++++++++++++++++ test/languages/php/datetime/test-strtotime.js | 6 +++++ 3 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cb1b2ed4c..02f71f4f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/php/datetime/strtotime.js b/src/php/datetime/strtotime.js index e8d01dd9e8..bcad5b6321 100644 --- a/src/php/datetime/strtotime.js +++ b/src/php/datetime/strtotime.js @@ -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', @@ -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) @@ -1332,6 +1356,7 @@ module.exports = function strtotime(str, now) { formats.timeShort12, formats.timeLong12, formats.mssqltime, + formats.oracledate, formats.timeShort24, formats.timeLong24, formats.iso8601long, diff --git a/test/languages/php/datetime/test-strtotime.js b/test/languages/php/datetime/test-strtotime.js index ce72813e4a..ea42aa14e8 100644 --- a/test/languages/php/datetime/test-strtotime.js +++ b/test/languages/php/datetime/test-strtotime.js @@ -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() + }) })