UNPKG

@benshi.ai/js-sdk

Version:

Benshi SDK

59 lines (48 loc) 2.01 kB
import { isISOLocal, offsetToISO8601, toISOLocal } from './utils' describe('Utils', () => { describe('ISO Formatter', () => { it('Should format a positive, no minutes offset', async () => { expect(offsetToISO8601(120)).toEqual('-0200') }) it('Should format a negative, no minutes offset', async () => { expect(offsetToISO8601(-120)).toEqual('+0200') }) it('Should format a positive offset with minutes', async () => { expect(offsetToISO8601(123)).toEqual('-0203') }) it('Should format a positive offset with minutes (II)', async () => { expect(offsetToISO8601(143)).toEqual('-0223') }) it('Should format a positive offset with minutes (III) - hour more than one digit', async () => { expect(offsetToISO8601(643)).toEqual('-1043') }) }) describe('ISO checker', () => { it('Should detect a timestamp as a correct RFC 3339 long format', () => { console.log(toISOLocal(new Date())) expect(isISOLocal(toISOLocal(new Date()))).toBeTruthy() }) it('Should detect a timestamp as a correct RFC 3339 long format', () => { expect(isISOLocal('1937-01-01T12:00:27.87+00:20')).toBeTruthy() }) it('Should detect a random string is not a correct RFC 3339 long format', () => { expect(isISOLocal('asdsafasfsafd')).toBeFalsy() }) it('Should detect a valid date is not a correct RFC 3339 long format', () => { expect(isISOLocal('1937-01-01')).toBeFalsy() }) it('Should detect a valid date and time is not a correct RFC 3339 long format', () => { expect(isISOLocal('1937-01-01T12:00:27')).toBeFalsy() }) it('Should detect a unix timestamp is not a correct RFC 3339 long format', () => { expect(isISOLocal(1663231725773)).toBeFalsy() }) it('Should detect a valid rfc3339 short is not a correct RFC 3339 long format', () => { expect(isISOLocal('1990-12-31T15:59:60-08:00')).toBeFalsy() }) }) })