Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chart start 01 instead 00 hour #32

Merged
merged 3 commits into from
Jan 16, 2025
Merged
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change log

## Unreleased
- Fix displaced 1 hour in curves chart

## 1.2.1 (2025-01-13)
- Avoid errors when a new maturity is added
- Upgrade somenergia-ui to 0.5.1 that fixes curve labels
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/services/curves.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ function array2datapoints(first_timestamp, values, step_ms = 60 * 60 * 1000) {

function timeInterval(scope, current_date) {
const start = new Date(current_date)
start.setHours(0)
start.setHours(1)
start.setMinutes(0)
start.setSeconds(0)
start.setMilliseconds(0)

if (scope === 'MONTHLY') {
start.setDate(1)
}
Expand Down
42 changes: 21 additions & 21 deletions frontend/src/services/curves.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,63 +84,63 @@ describe('index2time', () => {

describe('timeInterval', () => {
it('Day time interval, current start of day', () => {
expect(timeInterval('DAILY', new Date('2020-03-02T00:00:00'))).toStrictEqual([
new Date('2020-03-02T00:00:00'),
new Date('2020-03-03T00:00:00'),
expect(timeInterval('DAILY', new Date('2020-03-02T01:00:00'))).toStrictEqual([
new Date('2020-03-02T01:00:00'),
new Date('2020-03-03T01:00:00'),
])
})
it('Day time interval, within day', () => {
expect(timeInterval('DAILY', new Date('2020-03-02T09:00:00'))).toStrictEqual([
new Date('2020-03-02T00:00:00'),
new Date('2020-03-03T00:00:00'),
new Date('2020-03-02T01:00:00'),
new Date('2020-03-03T01:00:00'),
])
})
it('Day time interval, within day in UTC offset affects', () => {
expect(timeInterval('DAILY', new Date('2020-03-01T23:10:00Z'))).toStrictEqual([
new Date('2020-03-02T00:00:00'),
new Date('2020-03-03T00:00:00'),
new Date('2020-03-02T01:00:00'),
new Date('2020-03-03T01:00:00'),
])
})
it('Day time interval, within day in UTC offset does not affect', () => {
expect(timeInterval('DAILY', new Date('2020-03-02T22:10:00Z'))).toStrictEqual([
new Date('2020-03-02T00:00:00'),
new Date('2020-03-03T00:00:00'),
new Date('2020-03-02T01:00:00'),
new Date('2020-03-03T01:00:00'),
])
})
it('Month time interval, within month', () => {
expect(timeInterval('MONTHLY', new Date('2020-03-02T22:10:00Z'))).toStrictEqual([
new Date('2020-03-01T00:00:00'),
new Date('2020-04-01T00:00:00'),
new Date('2020-03-01T01:00:00'),
new Date('2020-04-01T01:00:00'),
])
})
it('Year time interval, within year', () => {
expect(timeInterval('YEARLY', new Date('2020-03-02T22:10:00Z'))).toStrictEqual([
new Date('2020-01-01T00:00:00'),
new Date('2021-01-01T00:00:00'),
new Date('2020-01-01T01:00:00'),
new Date('2021-01-01T01:00:00'),
])
})
it('Week time interval, monday', () => {
expect(timeInterval('WEEKLY', new Date('2020-03-02T22:10:00Z'))).toStrictEqual([
new Date('2020-03-02T00:00:00'),
new Date('2020-03-09T00:00:00'),
new Date('2020-03-02T01:00:00'),
new Date('2020-03-09T01:00:00'),
])
})
it('Week time interval, tuesday', () => {
expect(timeInterval('WEEKLY', new Date('2020-03-03T22:10:00Z'))).toStrictEqual([
new Date('2020-03-02T00:00:00'),
new Date('2020-03-09T00:00:00'),
new Date('2020-03-02T01:00:00'),
new Date('2020-03-09T01:00:00'),
])
})
it('Week time interval, sunday', () => {
expect(timeInterval('WEEKLY', new Date('2020-03-08T22:10:00Z'))).toStrictEqual([
new Date('2020-03-02T00:00:00'),
new Date('2020-03-09T00:00:00'),
new Date('2020-03-02T01:00:00'),
new Date('2020-03-09T01:00:00'),
])
})
it('Week time interval, sunday, crossing months', () => {
expect(timeInterval('WEEKLY', new Date('2020-03-01T22:10:00Z'))).toStrictEqual([
new Date('2020-02-24T00:00:00'),
new Date('2020-03-02T00:00:00'),
new Date('2020-02-24T01:00:00'),
new Date('2020-03-02T01:00:00'),
])
})
})
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/services/ovapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,16 @@ function invoicesZip(invoiceNumbers) {
})
}

export function setTimeInterval(first_timestamp_utc, last_timestamp_utc) {
let hourToAdd = 60 *60 *1000
first_timestamp_utc.setTime(first_timestamp_utc.getTime() + hourToAdd)
last_timestamp_utc.setDate(last_timestamp_utc.getDate() + 1)
last_timestamp_utc.setTime(last_timestamp_utc.getTime() + hourToAdd)
}

async function productionData(first_timestamp_utc, last_timestamp_utc, contract_number) {
const context = i18n.t('OVAPI.CONTEXT_PRODUCTION_DATA')
setTimeInterval(first_timestamp_utc, last_timestamp_utc)
return axios
.get('/api/production_data', {
params: {
Expand Down
Loading