Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
smart_date
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
smart_date
Merge requests
!82
Issue
#3420126
: Timezone is applied incorrectly to min and max values
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3420126
: Timezone is applied incorrectly to min and max values
issue/smart_date-3420126:3420126-timezone
into
4.0.x
Overview
0
Commits
1
Pipelines
0
Changes
1
Open
Himanshu Jhaloya
requested to merge
issue/smart_date-3420126:3420126-timezone
into
4.0.x
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Closes
#3420126
0
0
Merge request reports
Compare
4.0.x
4.0.x (HEAD)
and
latest version
latest version
fb775d45
1 commit,
1 year ago
1 file
+
51
−
42
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Plugin/views/filter/Date.php
+
51
−
42
Options
@@ -125,53 +125,62 @@ class Date extends CoreDate implements ContainerFactoryPluginInterface {
* Override parent method, which deals with dates as integers.
*/
protected
function
opBetween
(
$field
)
{
$timezone
=
$this
->
getTimezone
();
$granularity
=
$this
->
options
[
'value'
][
'granularity'
];
// Convert value to DateTimePlus for additional processing.
$a
=
new
DateTimePlus
(
$this
->
value
[
'min'
],
new
\DateTimeZone
(
$timezone
));
$b
=
new
DateTimePlus
(
$this
->
value
[
'max'
],
new
\DateTimeZone
(
$timezone
));
$a
=
new
DateTimePlus
(
$this
->
value
[
'min'
]);
$b
=
new
DateTimePlus
(
$this
->
value
[
'max'
]);
// Preserve the timezone of min and max values.
$timezoneA
=
$a
->
getTimezone
()
->
getName
();
$timezoneB
=
$b
->
getTimezone
()
->
getName
();
// Ensure that both values are in the same timezone.
if
(
$timezoneA
!==
$timezoneB
)
{
throw
new
\Exception
(
"Timezones for min and max values must be the same."
);
}
// Granularity requires some conversion.
if
(
$granularity
!=
'second'
)
{
$min
=
[
'year'
=>
$a
->
format
(
'Y'
),
'month'
=>
$a
->
format
(
'n'
),
'day'
=>
$a
->
format
(
'j'
),
'hour'
=>
$a
->
format
(
'G'
),
'minute'
=>
$a
->
format
(
'i'
),
'second'
=>
$a
->
format
(
's'
),
];
$max
=
[
'year'
=>
$b
->
format
(
'Y'
),
'month'
=>
$b
->
format
(
'n'
),
'day'
=>
$b
->
format
(
'j'
),
'hour'
=>
$b
->
format
(
'G'
),
'minute'
=>
$b
->
format
(
'i'
),
'second'
=>
$b
->
format
(
's'
),
];
switch
(
$granularity
)
{
case
'year'
:
$min
[
'month'
]
=
'01'
;
$max
[
'month'
]
=
'12'
;
$max
[
'day'
]
=
'31'
;
case
'month'
:
$min
[
'day'
]
=
'01'
;
if
(
$granularity
!=
'year'
)
{
$max
[
'day'
]
=
$b
->
format
(
't'
);
}
case
'day'
:
$min
[
'hour'
]
=
'00'
;
$max
[
'hour'
]
=
'23'
;
case
'hour'
:
$min
[
'minute'
]
=
'00'
;
$max
[
'minute'
]
=
'59'
;
case
'minute'
:
$min
[
'second'
]
=
'00'
;
$max
[
'second'
]
=
'59'
;
}
// Update the range with our altered values.
$a
=
$a
->
createFromArray
(
$min
);
$b
=
$b
->
createFromArray
(
$max
);
$min
=
[
'year'
=>
$a
->
format
(
'Y'
),
'month'
=>
$a
->
format
(
'n'
),
'day'
=>
$a
->
format
(
'j'
),
'hour'
=>
$a
->
format
(
'G'
),
'minute'
=>
$a
->
format
(
'i'
),
'second'
=>
$a
->
format
(
's'
),
];
$max
=
[
'year'
=>
$b
->
format
(
'Y'
),
'month'
=>
$b
->
format
(
'n'
),
'day'
=>
$b
->
format
(
'j'
),
'hour'
=>
$b
->
format
(
'G'
),
'minute'
=>
$b
->
format
(
'i'
),
'second'
=>
$b
->
format
(
's'
),
];
switch
(
$granularity
)
{
case
'year'
:
$min
[
'month'
]
=
'01'
;
$max
[
'month'
]
=
'12'
;
$max
[
'day'
]
=
'31'
;
case
'month'
:
$min
[
'day'
]
=
'01'
;
if
(
$granularity
!=
'year'
)
{
$max
[
'day'
]
=
$b
->
format
(
't'
);
}
case
'day'
:
$min
[
'hour'
]
=
'00'
;
$max
[
'hour'
]
=
'23'
;
case
'hour'
:
$min
[
'minute'
]
=
'00'
;
$max
[
'minute'
]
=
'59'
;
case
'minute'
:
$min
[
'second'
]
=
'00'
;
$max
[
'second'
]
=
'59'
;
}
// Update the range with our altered values.
$a
=
$a
->
createFromArray
(
$min
);
$b
=
$b
->
createFromArray
(
$max
);
}
// This is safe because we forced the provided values to DateTimePlus.
Loading