mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-17 05:13:32 +00:00
fix: excel parsing
This commit is contained in:
committed by
Carlos Valente
parent
ad46fac2d7
commit
dae6f84af0
@@ -1,4 +1,4 @@
|
||||
import { isTimeString } from './isTimeString';
|
||||
import { isISO8601, isTimeString } from './isTimeString';
|
||||
|
||||
describe('test isTimeString() function', () => {
|
||||
it('it validates time strings', () => {
|
||||
@@ -33,3 +33,16 @@ describe('test isTimeString() function handle AM/PM', () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('isISO8601()', () => {
|
||||
it('returns true for valid ISO 8601 date-time strings', () => {
|
||||
expect(isISO8601('1899-12-30T08:30:00.000Z')).toBe(true);
|
||||
expect(isISO8601('2022-01-01T00:00:00.000Z')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false for invalid ISO 8601 date-time strings', () => {
|
||||
expect(isISO8601('not a date')).toBe(false);
|
||||
expect(isISO8601('1899-12-30T08:30:00Z')).toBe(false); // missing milliseconds
|
||||
expect(isISO8601('1899-12-30 08:30:00.000Z')).toBe(false); // space instead of 'T'
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
/**
|
||||
* @description Validates a time string
|
||||
* @param {string} text - time string "23:00:12"
|
||||
* @returns {boolean} string represents time
|
||||
*/
|
||||
export const isTimeString = (text: string): boolean => {
|
||||
export function isTimeString(text: string): boolean {
|
||||
const regex = /^(?:(?:([01]?\d|2[0-3])[:,.])?([0-5]?\d)[:,.])?([0-5]?\d)?(\s)?([APap][Mm])?$/;
|
||||
return regex.test(text);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Validates a ISO8601 date-time string
|
||||
*/
|
||||
export function isISO8601(text: string): boolean {
|
||||
const regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
||||
return regex.test(text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user