Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hijri_format
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
hijri_format
Commits
df64e476
Commit
df64e476
authored
3 years ago
by
Saif Bataineh
Committed by
Yahya Al Hamad
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3255666
by SyfJO: Wrong DateTime when a website is using timezone other than UTC
parent
41f4acda
Branches
Branches containing commit
Tags
8.x-1.2
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Field/FieldFormatter/HijriFieldFormatter.php
+17
-3
17 additions, 3 deletions
src/Plugin/Field/FieldFormatter/HijriFieldFormatter.php
with
17 additions
and
3 deletions
src/Plugin/Field/FieldFormatter/HijriFieldFormatter.php
+
17
−
3
View file @
df64e476
...
...
@@ -122,12 +122,12 @@ class HijriFieldFormatter extends FormatterBase {
$class
=
get_class
(
$item
);
switch
(
$class
)
{
case
DateRangeItem
::
class
:
$date
[]
=
$this
->
hijriFormatManager
->
convertToHijri
(
strtotime
(
$item
->
getValue
()[
'value'
]),
$format
,
$is_indian
);
$date
[]
=
$this
->
hijriFormatManager
->
convertToHijri
(
strtotime
(
$item
->
getValue
()[
'end_value'
]),
$format
,
$is_indian
);
$date
[]
=
$this
->
hijriFormatManager
->
convertToHijri
(
$this
->
getUTCTimestamp
(
$item
->
getValue
()[
'value'
]),
$format
,
$is_indian
);
$date
[]
=
$this
->
hijriFormatManager
->
convertToHijri
(
$this
->
getUTCTimestamp
(
$item
->
getValue
()[
'end_value'
]),
$format
,
$is_indian
);
break
;
case
DateTimeItem
::
class
:
$value
=
strtotime
(
$item
->
getValue
()[
'value'
]);
$value
=
$this
->
getUTCTimestamp
(
$item
->
getValue
()[
'value'
]);
default
:
$value
=
$value
??
$item
->
getValue
()[
'value'
];
$date
[]
=
$this
->
hijriFormatManager
->
convertToHijri
(
$value
,
$format
,
$is_indian
);
...
...
@@ -141,4 +141,18 @@ class HijriFieldFormatter extends FormatterBase {
return
$elements
;
}
/**
* Gets the timestamp using UTC timezone.
*
* @param string $date_time_string
* DateTime string (e.g. 1996-04-24T12:00:00).
* @return int
* Timestamp using UTC timezone.
*/
private
function
getUTCTimestamp
(
string
$date_time_string
)
{
$timezone
=
new
\DateTimeZone
(
'UTC'
);
$date_time_string
=
str_replace
(
"T"
,
" "
,
$date_time_string
);
return
\DateTime
::
createFromFormat
(
'Y-m-d H:i:s'
,
$date_time_string
,
$timezone
)
->
getTimestamp
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment