Skip to content

Commit

Permalink
update t for sqlite, and o for sqlsrv.
Browse files Browse the repository at this point in the history
  • Loading branch information
MohannadNaj committed Jan 23, 2024
1 parent cd463bf commit 67d37dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Function/Date/EmulatedDateFormatTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function getEmulatableCharacterForSqlite(string $character): string|Ex
),
'n' => 'LTRIM(STRFTIME(\'%%m\', %s), \'0\')',
'o' => 'STRFTIME(\'%%Y\', %s, \'weekday 0\', \'-3 days\')',
't' => 'STRFTIME(\'%%d\', DATE(%s, \'+1 month\', \'start of month\', \'-1 day\'))',
't' => 'STRFTIME(\'%%d\', DATE(%s, \'start of month\', \'+1 month\', \'-1 day\'))',
'W' => 'PRINTF(\'%%02d\', (STRFTIME(\'%%j\', DATE(%s, \'-3 days\', \'weekday 4\')) - 1) / 7 + 1)',
'y' => 'SUBSTR(STRFTIME(\'%%Y\', %s), 3, 2)',
default => null,
Expand Down Expand Up @@ -186,7 +186,7 @@ protected function getEmulatableCharacterForSqlsrv(string $character): string|Ex
'l' => 'DATENAME(WEEKDAY, %s)',
'M' => 'LEFT(DATENAME(MONTH, %s), 3)',
'n' => 'CAST(MONTH(%s) AS VARCHAR(2))',
'o' => '(CASE WHEN DATEPART(iso_week, %s) = 1 AND MONTH(%s) = 12 THEN YEAR(%s) + 1 WHEN DATEPART(iso_week, %s) > 1 AND MONTH(%s) = 1 THEN YEAR(%s) - 1 ELSE YEAR(%s) END)',
'o' => 'YEAR(DATEADD(day, 3 - (DATEPART(dw, %s) + 5) %% 7, %s))',
't' => 'CAST(DAY(EOMONTH(%s)) AS VARCHAR(2))',
'U' => 'DATEDIFF(SECOND, \'1970-01-01\', %s)',
'w' => '(CAST(DATEPART(WEEKDAY, %s) AS VARCHAR(2)) - 1) %% 7',
Expand Down
8 changes: 8 additions & 0 deletions tests/Function/Date/DateFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@
'1970-06-01 00:00:00',
'1970-12-31 23:59:59',

'2005-01-01 00:00:00',
'2005-06-01 00:00:00',
'2005-12-31 23:59:59',

'2022-01-01 00:00:00',
'2022-03-31 00:00:00',
'2022-12-31 00:00:00',

'2023-01-01 00:00:00',
'2023-06-01 00:00:00',
'2023-12-31 23:59:59',
Expand Down

0 comments on commit 67d37dd

Please sign in to comment.