Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/views/infra/UsageRecords.vue
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ export default {
if (values.dateRange) {
if (this.$store.getters.usebrowsertimezone) {
params.startdate = dayjs.utc(dayjs(values.dateRange[0]).startOf('day')).format('YYYY-MM-DD HH:mm:ss')
params.enddate = dayjs.utc(dayjs(values.dateRange[0]).endOf('day')).format('YYYY-MM-DD HH:mm:ss')
params.enddate = dayjs.utc(dayjs(values.dateRange[1]).endOf('day')).format('YYYY-MM-DD HH:mm:ss')
} else {
params.startdate = dayjs(values.dateRange[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
params.enddate = dayjs(values.dateRange[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
Expand Down
69 changes: 69 additions & 0 deletions ui/tests/unit/views/infra/UsageRecords.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import UsageRecords from '@/views/infra/UsageRecords'

const originalTimezone = process.env.TZ

const getParams = (dateRange, useBrowserTimezone) => {
return UsageRecords.methods.getParams.call({
form: { dateRange },
handleRemoveFields: values => values,
page: 1,
pageSize: 20,
$store: {
getters: { usebrowsertimezone: useBrowserTimezone }
}
})
}

describe('Views > infra > UsageRecords.vue', () => {
beforeAll(() => {
process.env.TZ = 'Europe/London'
})

afterAll(() => {
if (originalTimezone === undefined) {
delete process.env.TZ
} else {
process.env.TZ = originalTimezone
}
})

describe('getParams()', () => {
it('uses both selected dates when converting a local-timezone range to UTC', () => {
const params = getParams(['2026-07-26', '2026-08-02'], true)

expect(params.startdate).toBe('2026-07-25 23:00:00')
expect(params.enddate).toBe('2026-08-02 22:59:59')
})

it('uses the selected end date when the range crosses daylight-saving time', () => {
const params = getParams(['2026-03-28', '2026-03-30'], true)

expect(params.startdate).toBe('2026-03-28 00:00:00')
expect(params.enddate).toBe('2026-03-30 22:59:59')
})

it('preserves both selected dates when browser-timezone conversion is disabled', () => {
const params = getParams(['2026-07-26', '2026-08-02'], false)

expect(params.startdate).toBe('2026-07-26 00:00:00')
expect(params.enddate).toBe('2026-08-02 23:59:59')
})
})
})