Skip to content

Commit 042ec7e

Browse files
authored
UI: fix usage records end date with local timezone (#13769)
1 parent 8d26cb3 commit 042ec7e

2 files changed

Lines changed: 83 additions & 2 deletions

File tree

ui/src/views/infra/UsageRecords.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ export default {
595595
page: page || this.page,
596596
pagesize: pageSize || this.pageSize
597597
}
598-
if (values.dateRange) {
598+
if (Array.isArray(values.dateRange) && values.dateRange[0] && values.dateRange[1]) {
599599
if (this.$store.getters.usebrowsertimezone) {
600600
params.startdate = dayjs.utc(dayjs(values.dateRange[0]).startOf('day')).format('YYYY-MM-DD HH:mm:ss')
601-
params.enddate = dayjs.utc(dayjs(values.dateRange[0]).endOf('day')).format('YYYY-MM-DD HH:mm:ss')
601+
params.enddate = dayjs.utc(dayjs(values.dateRange[1]).endOf('day')).format('YYYY-MM-DD HH:mm:ss')
602602
} else {
603603
params.startdate = dayjs(values.dateRange[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
604604
params.enddate = dayjs(values.dateRange[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
import dayjs from 'dayjs'
19+
import utc from 'dayjs/plugin/utc'
20+
import UsageRecords from '@/views/infra/UsageRecords'
21+
22+
dayjs.extend(utc)
23+
24+
const dateWithOffset = (date, offsetMinutes) => dayjs(date).utcOffset(offsetMinutes, true)
25+
26+
const getParams = (dateRange, useBrowserTimezone) => {
27+
return UsageRecords.methods.getParams.call({
28+
form: { dateRange },
29+
handleRemoveFields: values => values,
30+
page: 1,
31+
pageSize: 20,
32+
$store: {
33+
getters: { usebrowsertimezone: useBrowserTimezone }
34+
}
35+
})
36+
}
37+
38+
describe('Views > infra > UsageRecords.vue', () => {
39+
describe('getParams()', () => {
40+
it('uses both selected dates when converting a local-timezone range to UTC', () => {
41+
const params = getParams([
42+
dateWithOffset('2026-07-26', 60),
43+
dateWithOffset('2026-08-02', 60)
44+
], true)
45+
46+
expect(params.startdate).toBe('2026-07-25 23:00:00')
47+
expect(params.enddate).toBe('2026-08-02 22:59:59')
48+
})
49+
50+
it('uses the selected end date when the range crosses daylight-saving time', () => {
51+
const params = getParams([
52+
dateWithOffset('2026-03-28', 0),
53+
dateWithOffset('2026-03-30', 60)
54+
], true)
55+
56+
expect(params.startdate).toBe('2026-03-28 00:00:00')
57+
expect(params.enddate).toBe('2026-03-30 22:59:59')
58+
})
59+
60+
it('preserves both selected dates when browser-timezone conversion is disabled', () => {
61+
const params = getParams(['2026-07-26', '2026-08-02'], false)
62+
63+
expect(params.startdate).toBe('2026-07-26 00:00:00')
64+
expect(params.enddate).toBe('2026-08-02 23:59:59')
65+
})
66+
67+
it('omits date parameters when no range is selected', () => {
68+
const params = getParams([], true)
69+
70+
expect(params).not.toHaveProperty('startdate')
71+
expect(params).not.toHaveProperty('enddate')
72+
})
73+
74+
it('omits date parameters when the selected range is incomplete', () => {
75+
const params = getParams([dateWithOffset('2026-07-26', 60)], true)
76+
77+
expect(params).not.toHaveProperty('startdate')
78+
expect(params).not.toHaveProperty('enddate')
79+
})
80+
})
81+
})

0 commit comments

Comments
 (0)