Skip to content

Commit 702fb69

Browse files
Merge pull request #10 from OS366/feature/intelligence-module
Add tests for phantom.intelligence.dates.detect
2 parents d5c6526 + 799e2a7 commit 702fb69

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

phantom.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,3 +2152,63 @@ describe('phantom.dates', () => {
21522152
});
21532153
});
21542154
});
2155+
2156+
describe('phantom.intelligence.dates.detect', () => {
2157+
setupPhantomTests();
2158+
2159+
test('should detect ISO date format', () => {
2160+
expect(phantom.intelligence.dates.detect('2024-12-16')).toBe('yyyy-MM-dd');
2161+
});
2162+
2163+
test('should detect ISO datetime format', () => {
2164+
expect(phantom.intelligence.dates.detect('2024-12-16T10:30:00')).toBe("yyyy-MM-dd'T'HH:mm:ss");
2165+
});
2166+
2167+
test('should detect ISO datetime with milliseconds', () => {
2168+
expect(phantom.intelligence.dates.detect('2024-12-16T10:30:00.123')).toBe("yyyy-MM-dd'T'HH:mm:ss.SSS");
2169+
});
2170+
2171+
test('should detect ISO datetime with timezone Z', () => {
2172+
expect(phantom.intelligence.dates.detect('2024-12-16T10:30:00Z')).toBe("yyyy-MM-dd'T'HH:mm:ss'Z'");
2173+
});
2174+
2175+
test('should detect US date format with slash', () => {
2176+
expect(phantom.intelligence.dates.detect('12/16/2024')).toBe('MM/dd/yyyy');
2177+
});
2178+
2179+
test('should detect US date format with dash', () => {
2180+
expect(phantom.intelligence.dates.detect('12-16-2024')).toBe('MM-dd-yyyy');
2181+
});
2182+
2183+
test('should detect EU date format with locale hint', () => {
2184+
expect(phantom.intelligence.dates.detect('16/12/2024', { locale: 'EU' })).toBe('dd/MM/yyyy');
2185+
});
2186+
2187+
test('should detect compact date format yyyyMMdd', () => {
2188+
expect(phantom.intelligence.dates.detect('20241216')).toBe('yyyyMMdd');
2189+
});
2190+
2191+
test('should detect compact datetime format yyyyMMddHHmmss', () => {
2192+
expect(phantom.intelligence.dates.detect('20241216103000')).toBe('yyyyMMddHHmmss');
2193+
});
2194+
2195+
test('should detect compact datetime with millis yyyyMMddHHmmssSSS', () => {
2196+
expect(phantom.intelligence.dates.detect('20241216103000123')).toBe('yyyyMMddHHmmssSSS');
2197+
});
2198+
2199+
test('should throw error for invalid date string', () => {
2200+
expect(() => phantom.intelligence.dates.detect('not-a-date')).toThrow('Invalid date');
2201+
});
2202+
2203+
test('should throw error for invalid compact date', () => {
2204+
expect(() => phantom.intelligence.dates.detect('20241316')).toThrow('Invalid date');
2205+
});
2206+
2207+
test('should throw error for null input', () => {
2208+
expect(() => phantom.intelligence.dates.detect(null)).toThrow();
2209+
});
2210+
2211+
test('should throw error for empty string', () => {
2212+
expect(() => phantom.intelligence.dates.detect('')).toThrow();
2213+
});
2214+
});

wiki/Date-Operations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var format = phantom.intelligence.dates.detect("16/12/2024", { locale: "EU" });
4141

4242
// Detect datetime with timezone
4343
var format = phantom.intelligence.dates.detect("2024-12-16T10:30:00Z");
44-
// Output: "yyyy-MM-dd'T'HH:mm:ssX"
44+
// Output: "yyyy-MM-dd'T'HH:mm:ss'Z'"
4545

4646
// Detect compact ISO format
4747
var format = phantom.intelligence.dates.detect("20241216");

0 commit comments

Comments
 (0)