Skip to content

Commit

Permalink
fix: [UIE-8446] - restore backup date and time fix (#11628)
Browse files Browse the repository at this point in the history
* fix: [UIE-8446] - restore backup time fix

* Added changeset: Database restore backup timezone inconsistency

* fix: [UIE-8446] - update CHANGELOG

* fix: [UIE-8446] - update CHANGELOG
  • Loading branch information
mpolotsk-akamai authored Feb 10, 2025
1 parent 15b219b commit a048132
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/manager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- Buggy Copy Token behavior on LKE details page ([#11592](https://github.com/linode/manager/pull/11592))
- Longview Detail id param not found (local only) ([#11599](https://github.com/linode/manager/pull/11599))
- Database restore backup timezone inconsistency ([#11628](https://github.com/linode/manager/pull/11628))

### Tech Stories:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const DatabaseBackups = (props: Props) => {
const isDefaultDatabase = database?.platform === 'rdbms-default';

const oldestBackup = database?.oldest_restore_time
? DateTime.fromISO(database.oldest_restore_time)
? DateTime.fromISO(`${database.oldest_restore_time}Z`)
: null;

const unableToRestoreCopy = !oldestBackup
Expand Down Expand Up @@ -206,6 +206,9 @@ export const DatabaseBackups = (props: Props) => {
<FormControl style={{ marginTop: 0 }}>
{/* TODO: Replace Time Select to the own custom date-time picker component when it's ready */}
<Autocomplete
disabled={
disabled || !selectedDate || versionOption === 'newest'
}
getOptionDisabled={(option) =>
isTimeOutsideBackup(
option.value,
Expand All @@ -231,9 +234,6 @@ export const DatabaseBackups = (props: Props) => {
}}
autoComplete={false}
className={classes.timeAutocomplete}
disabled={
disabled || !selectedDate || versionOption === 'newest'
}
label=""
onChange={(_, newTime) => setSelectedTime(newTime)}
options={TIME_OPTIONS}
Expand Down
25 changes: 21 additions & 4 deletions packages/manager/src/features/Databases/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isDefaultDatabase,
isLegacyDatabase,
isTimeOutsideBackup,
toFormatedDate,
toISOString,
upgradableVersions,
useIsDatabasesEnabled,
Expand Down Expand Up @@ -359,30 +360,46 @@ describe('isDateOutsideBackup', () => {
describe('isTimeOutsideBackup', () => {
it('should return true when hour + selected date is before oldest backup', () => {
const selectedDate = DateTime.fromISO('2024-10-02');
const oldestBackup = DateTime.fromISO('2024-10-02T09:00:00');
const oldestBackup = DateTime.fromISO('2024-10-02T09:00:00Z');
const result = isTimeOutsideBackup(8, selectedDate, oldestBackup);
expect(result).toEqual(true);
});

it('should return false when hour + selected date is equal to the oldest backup', () => {
const selectedDate = DateTime.fromISO('2024-10-02');
const oldestBackup = DateTime.fromISO('2024-10-02T09:00:00');
const oldestBackup = DateTime.fromISO('2024-10-02T09:00:00Z');
const result = isTimeOutsideBackup(9, selectedDate, oldestBackup);
expect(result).toEqual(false);
});

it('should return false when hour + selected date is after the oldest backup', () => {
const selectedDate = DateTime.fromISO('2024-10-03');
const oldestBackup = DateTime.fromISO('2024-10-02T09:00:00');
const oldestBackup = DateTime.fromISO('2024-10-02T09:00:00Z');
const result = isTimeOutsideBackup(1, selectedDate, oldestBackup);
expect(result).toEqual(false);
});
});

describe('toFormatedDate', () => {
it('should convert a date and time to the format YYYY-MM-DD HH:mm for the dialog', () => {
const selectedDate = DateTime.fromObject({ day: 15, month: 1, year: 2025 });
const selectedTime: TimeOption = { label: '14:00', value: 14 };
const result = toFormatedDate(selectedDate, selectedTime.value);
expect(result).toContain('2025-01-15 14:00');
});
it('should handle newest full backup plus incremental option correctly in UTC', () => {
const selectedDate = null;
const today = DateTime.utc();
const mockTodayWithHours = `${today.toISODate()} ${today.hour}:00`;
const result = toFormatedDate(selectedDate, undefined);
expect(result).toContain(mockTodayWithHours);
});
});

describe('toISOString', () => {
it('should convert a date and time to ISO string format', () => {
const selectedDate = DateTime.fromObject({ day: 15, month: 5, year: 2023 });
const selectedTime: TimeOption = { label: '02:00', value: 14 };
const selectedTime: TimeOption = { label: '14:00', value: 14 };
const result = toISOString(selectedDate, selectedTime.value);
expect(result).toContain('2023-05-15T14:00');
});
Expand Down
8 changes: 4 additions & 4 deletions packages/manager/src/features/Databases/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const isDateOutsideBackup = (
if (!oldestBackup) {
return true;
}
const today = DateTime.now();
const today = DateTime.utc();
return date < oldestBackup || date > today;
};

Expand Down Expand Up @@ -169,10 +169,10 @@ export const toSelectedDateTime = (
time: number = 0
) => {
const isoDate = selectedDate?.toISODate();
const isoTime = DateTime.now()
const isoTime = DateTime.utc()
.set({ hour: time, minute: 0 })
?.toISOTime({ includeOffset: false });
return DateTime.fromISO(`${isoDate}T${isoTime}`);
return DateTime.fromISO(`${isoDate}T${isoTime}`, { zone: 'UTC' });
};

/**
Expand All @@ -187,7 +187,7 @@ export const toFormatedDate = (
selectedDate?: DateTime | null,
selectedTime?: number
) => {
const today = DateTime.now();
const today = DateTime.utc();
const isoDate =
selectedDate && selectedTime
? toISOString(selectedDate!, selectedTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const DatabaseMigrationInfoBanner = () => {
Legacy clusters decommission
</Typography>
<Typography lineHeight="20px">
Legacy database clusters will only be available until the end of 2025.
At that time, we’ll migrate your clusters to the new solution. For
Legacy database clusters will only be available until the end of June
2025. At that time, we’ll migrate your clusters to the new solution. For
questions regarding the new database clusters or the migration,{' '}
<SupportLink entity={{ type: 'database_id' }} text="contact support" />.
</Typography>
Expand Down

0 comments on commit a048132

Please sign in to comment.