Merge pull request #4389 from backstage/catalog-port-to-luxon
Port catalog plugin to Luxon
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog': patch
|
||||
---
|
||||
|
||||
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",
|
||||
"moment": "^2.26.0",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-helmet": "6.1.0",
|
||||
|
||||
@@ -14,36 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import moment from 'moment';
|
||||
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 moment(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 or an array of format strings to validate against.
|
||||
* @returns {bool} Whether the date is valid or not according to the format.
|
||||
*/
|
||||
export function isValidDateAndFormat(date, format) {
|
||||
return moment(date, format, true).isValid();
|
||||
}
|
||||
|
||||
export function relativeTime(timestamp) {
|
||||
return moment(timestamp).fromNow();
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -14,20 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { isValidDateAndFormat, getTimeBasedGreeting } from './timeUtil';
|
||||
|
||||
it('validates time format', () => {
|
||||
const valid = isValidDateAndFormat(
|
||||
'1970-01-01T00:00:00',
|
||||
'YYYY-MM-DD[T]HH:mm:ss',
|
||||
);
|
||||
const invalid = isValidDateAndFormat(
|
||||
'1970/01/01T00:00:00',
|
||||
'YYYY-MM-DD[T]HH:mm:ss',
|
||||
);
|
||||
expect(valid).toBe(true);
|
||||
expect(invalid).toBe(false);
|
||||
});
|
||||
import { getTimeBasedGreeting } from './timeUtil';
|
||||
|
||||
it('has greeting and language', () => {
|
||||
const greeting = getTimeBasedGreeting();
|
||||
|
||||
Reference in New Issue
Block a user