File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,21 @@ describe('timepicker utilities', () => {
56
56
expect ( parseInterval ( '3M' ) ) . toBe ( 180 ) ;
57
57
expect ( parseInterval ( '3S' ) ) . toBe ( 3 ) ;
58
58
} ) ;
59
+
60
+ it ( 'should parse interval with space' , ( ) => {
61
+ expect ( parseInterval ( '3 h' ) ) . toBe ( 10_800 ) ;
62
+ expect ( parseInterval ( '6 h' ) ) . toBe ( 21_600 ) ;
63
+ } ) ;
64
+
65
+ it ( 'should handle long versions of units' , ( ) => {
66
+ expect ( parseInterval ( '1 hour' ) ) . toBe ( 3600 ) ;
67
+ expect ( parseInterval ( '3 hours' ) ) . toBe ( 10_800 ) ;
68
+ expect ( parseInterval ( '1 minute' ) ) . toBe ( 60 ) ;
69
+ expect ( parseInterval ( '3 min' ) ) . toBe ( 180 ) ;
70
+ expect ( parseInterval ( '3 minutes' ) ) . toBe ( 180 ) ;
71
+ expect ( parseInterval ( '1 second' ) ) . toBe ( 1 ) ;
72
+ expect ( parseInterval ( '10 seconds' ) ) . toBe ( 10 ) ;
73
+ } ) ;
59
74
} ) ;
60
75
61
76
describe ( 'generateOptions' , ( ) => {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import {InjectionToken} from '@angular/core';
10
10
import { DateAdapter , MatDateFormats } from '@angular/material/core' ;
11
11
12
12
/** Pattern that interval strings have to match. */
13
- const INTERVAL_PATTERN = / ^ ( \d * \. ? \d + ) ( h | m | s ) ? $ / i;
13
+ const INTERVAL_PATTERN = / ^ ( \d * \. ? \d + ) \s * ( h | h o u r | h o u r s | m | m i n | m i n u t e | m i n u t e s | s | s e c o n d | s e c o n d s ) ? $ / i;
14
14
15
15
/**
16
16
* Object that can be used to configure the default options for the timepicker component.
@@ -62,9 +62,9 @@ export function parseInterval(value: number | string | null): number | null {
62
62
return null ;
63
63
}
64
64
65
- if ( unit === 'h' ) {
65
+ if ( unit === 'h' || unit === 'hour' || unit === 'hours' ) {
66
66
result = amount * 3600 ;
67
- } else if ( unit === 'm' ) {
67
+ } else if ( unit === 'm' || unit === 'min' || unit === 'minute' || unit === 'minutes' ) {
68
68
result = amount * 60 ;
69
69
} else {
70
70
result = amount ;
You can’t perform that action at this time.
0 commit comments