import { DateUtils } from './date.utils'

describe('DateUtils', () => {
	describe('isIsoDateString', () => {
		describe('valid ISO 8601 date strings', () => {
			it('should match date only format YYYY-MM-DD', () => {
				expect(DateUtils.isIsoDateString('2024-01-15')).toBe(true)
			})

			it('should match date with time format YYYY-MM-DDTHH:mm:ss', () => {
				expect(DateUtils.isIsoDateString('2024-01-15T10:30:45')).toBe(true)
			})

			it('should match date with time and milliseconds', () => {
				expect(DateUtils.isIsoDateString('2024-01-15T10:30:45.123')).toBe(true)
			})

			it('should match date with time and Z timezone', () => {
				expect(DateUtils.isIsoDateString('2024-01-15T10:30:45Z')).toBe(true)
			})

			it('should match date with time and UTC offset', () => {
				expect(DateUtils.isIsoDateString('2024-01-15T10:30:45+05:30')).toBe(true)
			})

			it('should match date with space instead of T separator', () => {
				expect(DateUtils.isIsoDateString('2024-01-15 10:30:45')).toBe(true)
			})

			it('should match date with space separator and timezone', () => {
				expect(DateUtils.isIsoDateString('2024-01-15 10:30:45Z')).toBe(true)
			})

			it('should match date with time without seconds', () => {
				expect(DateUtils.isIsoDateString('2024-01-15T10:30')).toBe(true)
			})

			it('should match date with milliseconds and timezone', () => {
				expect(DateUtils.isIsoDateString('2024-01-15T10:30:45.999+00:00')).toBe(true)
			})

			it('should match leap year date', () => {
				expect(DateUtils.isIsoDateString('2024-02-29')).toBe(true)
			})

			it('should match December 31st', () => {
				expect(DateUtils.isIsoDateString('2024-12-31')).toBe(true)
			})

			it('should match January 1st', () => {
				expect(DateUtils.isIsoDateString('2024-01-01')).toBe(true)
			})
		})

		describe('invalid ISO 8601 date strings', () => {
			it('should not match bare timezone offset', () => {
				expect(DateUtils.isIsoDateString('+05:30')).toBe(false)
			})

			it('should not match timezone label with offset', () => {
				expect(DateUtils.isIsoDateString('UTC+05:30')).toBe(false)
			})

			it('should not match just a year', () => {
				expect(DateUtils.isIsoDateString('2024')).toBe(false)
			})

			it('should not match year and month only', () => {
				expect(DateUtils.isIsoDateString('2024-01')).toBe(false)
			})

			it('should not match time without date', () => {
				expect(DateUtils.isIsoDateString('10:30:45')).toBe(false)
			})

			it('should not match empty string', () => {
				expect(DateUtils.isIsoDateString('')).toBe(false)
			})

			it('should not match random string', () => {
				expect(DateUtils.isIsoDateString('hello world')).toBe(false)
			})

			it('should not match date with wrong separator', () => {
				expect(DateUtils.isIsoDateString('2024/01/15')).toBe(false)
			})

			it('should not match malformed ISO string', () => {
				expect(DateUtils.isIsoDateString('2024-01-15T')).toBe(false)
			})

			it('should not match date with extra characters at end', () => {
				expect(DateUtils.isIsoDateString('2024-01-15 extra')).toBe(false)
			})
		})
	})
})
