|
1 | 1 | import { cloneValue, isObject, isDate, getCurrencyCode, getCurrencySymbol, getLocaleFirstDayOfWeek, formatDate, formatCurrency, formatPercent, formatNumber, getLocaleDateFormat, getLocaleDateTimeFormat } from './utils'; |
2 | 2 | import { SampleTestData } from '../test-utils/sample-test-data.spec'; |
| 3 | +import { toggleIgxAngularLocalization } from './i18n/resources'; |
3 | 4 |
|
4 | 5 | describe('Utils', () => { |
5 | 6 | const complexObject = { |
@@ -290,25 +291,45 @@ describe('Utils', () => { |
290 | 291 | }) |
291 | 292 |
|
292 | 293 | describe('date formatting', () => { |
293 | | - it('should format string to dateTime', () => { |
| 294 | + it('should format string to dateTime using Angular', () => { |
| 295 | + // Angular expects time to be already in local time so we don't exact check timezone... |
| 296 | + expect(formatDate('2025-01-25T14:15:00', 'short', 'en-US')).toEqual('1/25/25, 2:15 PM'); |
| 297 | + expect(formatDate('2025-01-25T14:15:00', 'medium', 'en-US')).toEqual('Jan 25, 2025, 2:15:00 PM'); |
| 298 | + expect(formatDate('2025-01-25T14:15:00', 'long', 'en-US')).toContain('January 25, 2025 at 2:15:00 PM GMT'); |
| 299 | + expect(formatDate('2025-01-25T14:15:00', 'full', 'en-US')).toContain('Saturday, January 25, 2025 at 2:15:00 PM GMT'); |
| 300 | + }); |
| 301 | + |
| 302 | + it('should format string to dateTime using Intl', () => { |
| 303 | + toggleIgxAngularLocalization(false); |
294 | 304 | expect(formatDate('2025-01-25T14:15:00', 'short', 'en-US', "Europe/Sofia")).toEqual('1/25/25, 2:15 PM'); |
295 | 305 | expect(formatDate('2025-01-25T14:15:00', 'medium', 'en-US', "Europe/Sofia")).toEqual('Jan 25, 2025, 2:15:00 PM'); |
296 | 306 | expect(formatDate('2025-01-25T14:15:00', 'long', 'en-US', "Europe/Sofia")).toEqual('January 25, 2025 at 2:15:00 PM GMT+2'); |
297 | | - expect(formatDate('2025-01-25T14:15:00', 'full', 'en-US', "Europe/Sofia")).toEqual('Saturday, January 25, 2025 at 2:15:00 PM GMT+02:00'); |
| 307 | + expect(formatDate('2025-01-25T14:15:00', 'full', 'en-US', "Europe/Sofia")).toEqual('Saturday, January 25, 2025 at 2:15:00 PM Eastern European Standard Time'); |
| 308 | + toggleIgxAngularLocalization(true); |
298 | 309 | }); |
299 | 310 |
|
300 | | - it('should format string to date', () => { |
| 311 | + it('should format string to date using Angular', () => { |
301 | 312 | expect(formatDate('2025-01-25T14:15:00', 'shortDate', 'en-US', "Europe/Sofia")).toEqual('1/25/25'); |
302 | 313 | expect(formatDate('2025-01-25T14:15:00', 'mediumDate', 'en-US', "Europe/Sofia")).toEqual('Jan 25, 2025'); |
303 | 314 | expect(formatDate('2025-01-25T14:15:00', 'longDate', 'en-US', "Europe/Sofia")).toEqual('January 25, 2025'); |
304 | 315 | expect(formatDate('2025-01-25T14:15:00', 'fullDate', 'en-US', "Europe/Sofia")).toEqual('Saturday, January 25, 2025'); |
305 | 316 | }); |
306 | 317 |
|
307 | | - it('should format string to time', () => { |
| 318 | + it('should format string to time using Angular', () => { |
| 319 | + // Angular expects time to be already in local time so we don't exact check timezone... |
| 320 | + expect(formatDate('2025-01-25T14:15:00', 'shortTime', 'en-US')).toEqual('2:15 PM'); |
| 321 | + expect(formatDate('2025-01-25T14:15:00', 'mediumTime', 'en-US')).toEqual('2:15:00 PM'); |
| 322 | + expect(formatDate('2025-01-25T14:15:00', 'longTime', 'en-US')).toContain('2:15:00 PM GMT'); |
| 323 | + expect(formatDate('2025-01-25T14:15:00', 'fullTime', 'en-US')).toContain('2:15:00 PM GMT'); |
| 324 | + }); |
| 325 | + |
| 326 | + it('should format string to time using Intl', () => { |
| 327 | + toggleIgxAngularLocalization(false); |
308 | 328 | expect(formatDate('2025-01-25T14:15:00', 'shortTime', 'en-US', "Europe/Sofia")).toEqual('2:15 PM'); |
309 | 329 | expect(formatDate('2025-01-25T14:15:00', 'mediumTime', 'en-US', "Europe/Sofia")).toEqual('2:15:00 PM'); |
310 | 330 | expect(formatDate('2025-01-25T14:15:00', 'longTime', 'en-US', "Europe/Sofia")).toEqual('2:15:00 PM GMT+2'); |
311 | | - expect(formatDate('2025-01-25T14:15:00', 'fullTime', 'en-US', "Europe/Sofia")).toEqual('2:15:00 PM GMT+02:00'); |
| 331 | + expect(formatDate('2025-01-25T14:15:00', 'fullTime', 'en-US', "Europe/Sofia")).toEqual('2:15:00 PM Eastern European Standard Time'); |
| 332 | + toggleIgxAngularLocalization(true); |
312 | 333 | }); |
313 | 334 |
|
314 | 335 | it('should format string to custom format', () => { |
|
0 commit comments