Remove unused functions and luxon
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
'@backstage/plugin-catalog': patch
|
||||
---
|
||||
|
||||
Migrated the package from using moment to Luxon. #4278
|
||||
Removed unused functions and the moment library. #4278
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
"@types/react": "^16.9",
|
||||
"classnames": "^2.2.6",
|
||||
"git-url-parse": "^11.4.4",
|
||||
"luxon": "^1.25.0",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-helmet": "6.1.0",
|
||||
|
||||
@@ -14,36 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DateTime } from 'luxon';
|
||||
import goodMorning from './locales/goodMorning.locales.json';
|
||||
import goodAfternoon from './locales/goodAfternoon.locales.json';
|
||||
import goodEvening from './locales/goodEvening.locales.json';
|
||||
|
||||
/**
|
||||
* Validates that a date is a valid ISO string.
|
||||
*
|
||||
* @param date A date string
|
||||
* @returns {bool} Whether the date is valid or not.
|
||||
*/
|
||||
export function isValidDate(date) {
|
||||
return DateTime.fromISO(date).isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that a date is a valid ISO string and a specific format.
|
||||
*
|
||||
* @param date A date string
|
||||
* @param format A format string to validate against. See https://moment.github.io/luxon/docs/manual/parsing.html#table-of-tokens for reference.
|
||||
* @returns {bool} Whether the date is valid or not according to the format.
|
||||
*/
|
||||
export function isValidDateAndFormat(date, format) {
|
||||
return DateTime.fromFormat(date, format).isValid;
|
||||
}
|
||||
|
||||
export function relativeTime(timestamp) {
|
||||
return DateTime.fromISO(timestamp).toRelative();
|
||||
}
|
||||
|
||||
// Select a large random integer at startup, to prevent the greetings to change every time the user
|
||||
// navigates.
|
||||
const greetingRandomSeed = Math.floor(Math.random() * 1000000);
|
||||
|
||||
@@ -19,25 +19,6 @@ import {
|
||||
isValidDateAndFormat,
|
||||
getTimeBasedGreeting,
|
||||
} from './timeUtil';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
it('validate isValidDate', () => {
|
||||
expect(isValidDate(DateTime.local().toISO())).toBeTruthy();
|
||||
expect(isValidDate('2021-02-04 15:00:10')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('validates time format', () => {
|
||||
const valid = isValidDateAndFormat(
|
||||
'1970-01-01 00:00:00',
|
||||
'yyyy-MM-dd hh:mm:ss',
|
||||
);
|
||||
const invalid = isValidDateAndFormat(
|
||||
'1970-01-01T00:00:00',
|
||||
'yyyy-MM-ddThh:mm:ss',
|
||||
);
|
||||
expect(valid).toBeTruthy();
|
||||
expect(invalid).toBeFalsy();
|
||||
});
|
||||
|
||||
it('has greeting and language', () => {
|
||||
const greeting = getTimeBasedGreeting();
|
||||
|
||||
Reference in New Issue
Block a user