Skip to content

Commit 4fff262

Browse files
committed
fix(datetime): format seconds token
Closes #6951
1 parent 3cd31c3 commit 4fff262

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

src/components/datetime/test/basic/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {ionicBootstrap} from '../../../../../src';
77
})
88
class E2EPage {
99
wwwInvented = '1989';
10-
time = '13:47';
10+
time = '13:47:00';
1111
netscapeReleased = '1994-12-15T13:47:20.789';
1212
operaReleased = '1995-04-15';
1313
firefoxReleased = '2002-09-23T15:03:46.789';

src/components/datetime/test/basic/main.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@
8787
{{convertedDate}}
8888
</p>
8989

90+
<ion-item>
91+
<ion-label>HH:mm:ss</ion-label>
92+
<ion-datetime displayFormat="HH:mm:ss" [(ngModel)]="time"></ion-datetime>
93+
</ion-item>
94+
9095
</ion-content>

src/util/datetime-util.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function renderTextFormat(format: string, value: any, date: DateTimeData,
6666

6767
if (format === FORMAT_YY || format === FORMAT_MM ||
6868
format === FORMAT_DD || format === FORMAT_HH ||
69-
format === FORMAT_mm) {
69+
format === FORMAT_mm || format === FORMAT_ss) {
7070
return twoDigit(value);
7171
}
7272

@@ -136,6 +136,12 @@ export function dateValueRange(format: string, min: DateTimeData, max: DateTimeD
136136
opts.push(i);
137137
}
138138

139+
} else if (format === FORMAT_ss || format === FORMAT_s) {
140+
// seconds
141+
for (i = 0; i < 60; i++) {
142+
opts.push(i);
143+
}
144+
139145
} else if (format === FORMAT_A || format === FORMAT_a) {
140146
// AM/PM
141147
opts.push('am', 'pm');
@@ -432,6 +438,8 @@ const FORMAT_hh = 'hh';
432438
const FORMAT_h = 'h';
433439
const FORMAT_mm = 'mm';
434440
const FORMAT_m = 'm';
441+
const FORMAT_ss = 'ss';
442+
const FORMAT_s = 's';
435443
const FORMAT_A = 'A';
436444
const FORMAT_a = 'a';
437445

@@ -447,11 +455,13 @@ const FORMAT_KEYS = [
447455
{ f: FORMAT_HH, k: 'hour' },
448456
{ f: FORMAT_hh, k: 'hour' },
449457
{ f: FORMAT_mm, k: 'minute' },
458+
{ f: FORMAT_ss, k: 'second' },
450459
{ f: FORMAT_M, k: 'month' },
451460
{ f: FORMAT_D, k: 'day' },
452461
{ f: FORMAT_H, k: 'hour' },
453462
{ f: FORMAT_h, k: 'hour' },
454463
{ f: FORMAT_m, k: 'minute' },
464+
{ f: FORMAT_s, k: 'second' },
455465
{ f: FORMAT_A, k: 'ampm' },
456466
{ f: FORMAT_a, k: 'ampm' },
457467
];

src/util/test/datetime-util.spec.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('convertDataToISO', () => {
114114
expect(str).toEqual('13:47:20.789');
115115
});
116116

117-
it('should convert DateTimeData to HH:mm:SS string', () => {
117+
it('should convert DateTimeData to HH:mm:ss string', () => {
118118
var data: datetime.DateTimeData = {
119119
year: null,
120120
month: null,
@@ -201,6 +201,11 @@ describe('convertFormatToKey', () => {
201201
expect(datetime.convertFormatToKey('m')).toEqual('minute');
202202
});
203203

204+
it('should convert second formats to their DateParse key', () => {
205+
expect(datetime.convertFormatToKey('ss')).toEqual('second');
206+
expect(datetime.convertFormatToKey('s')).toEqual('second');
207+
});
208+
204209
it('should convert am/pm formats to their DateParse key', () => {
205210
expect(datetime.convertFormatToKey('A')).toEqual('ampm');
206211
expect(datetime.convertFormatToKey('a')).toEqual('ampm');
@@ -317,24 +322,26 @@ describe('parseTemplate', () => {
317322
expect(formats[1]).toEqual('mm');
318323
});
319324

320-
it('should get formats from template "m mm h hh H HH D DD DDD DDDD M MM MMM MMMM YY YYYY"', () => {
321-
var formats = datetime.parseTemplate('m mm h hh H HH D DD DDD DDDD M MM MMM MMMM YY YYYY');
322-
expect(formats[0]).toEqual('m');
323-
expect(formats[1]).toEqual('mm');
324-
expect(formats[2]).toEqual('h');
325-
expect(formats[3]).toEqual('hh');
326-
expect(formats[4]).toEqual('H');
327-
expect(formats[5]).toEqual('HH');
328-
expect(formats[6]).toEqual('D');
329-
expect(formats[7]).toEqual('DD');
330-
expect(formats[8]).toEqual('DDD');
331-
expect(formats[9]).toEqual('DDDD');
332-
expect(formats[10]).toEqual('M');
333-
expect(formats[11]).toEqual('MM');
334-
expect(formats[12]).toEqual('MMM');
335-
expect(formats[13]).toEqual('MMMM');
336-
expect(formats[14]).toEqual('YY');
337-
expect(formats[15]).toEqual('YYYY');
325+
it('should get formats from template "s ss m mm h hh H HH D DD DDD DDDD M MM MMM MMMM YY YYYY"', () => {
326+
var formats = datetime.parseTemplate('s ss m mm h hh H HH D DD DDD DDDD M MM MMM MMMM YY YYYY');
327+
expect(formats[0]).toEqual('s');
328+
expect(formats[1]).toEqual('ss');
329+
expect(formats[2]).toEqual('m');
330+
expect(formats[3]).toEqual('mm');
331+
expect(formats[4]).toEqual('h');
332+
expect(formats[5]).toEqual('hh');
333+
expect(formats[6]).toEqual('H');
334+
expect(formats[7]).toEqual('HH');
335+
expect(formats[8]).toEqual('D');
336+
expect(formats[9]).toEqual('DD');
337+
expect(formats[10]).toEqual('DDD');
338+
expect(formats[11]).toEqual('DDDD');
339+
expect(formats[12]).toEqual('M');
340+
expect(formats[13]).toEqual('MM');
341+
expect(formats[14]).toEqual('MMM');
342+
expect(formats[15]).toEqual('MMMM');
343+
expect(formats[16]).toEqual('YY');
344+
expect(formats[17]).toEqual('YYYY');
338345
});
339346

340347
it('should get formats from template YYMMMMDDHHmm', () => {

0 commit comments

Comments
 (0)