1
- import { set , setDay , isPast , addBusinessDays , format as fnsFormat , addDays , addWeeks , addMonths , addYears , startOfDay , startOfWeek , startOfMonth , startOfYear } from 'date-fns' ;
1
+ import { set , setDay , isPast , addBusinessDays , addDays , addWeeks , addMonths , addYears , startOfDay , startOfWeek , startOfMonth , startOfYear } from 'date-fns' ;
2
2
import { Localization } from '../localization' ;
3
3
4
4
const dateNames = { // can depend on locale, can be fetched from CONFIG
@@ -29,7 +29,7 @@ const parseHumanDate = function(input: string): Date | undefined {
29
29
const case1a : RegExp = new RegExp ( `next (${ periods . join ( '|' ) } )` , 'gi' ) ;
30
30
if ( matchArray = case1a . exec ( input ) ) {
31
31
// console.log(matchArray);
32
- console . log ( 'case 1a: next <period>' ) ;
32
+ // console.log('case 1a: next <period>');
33
33
const periodIndex : number = periods . indexOf ( matchArray [ 1 ] ) ;
34
34
parsedDate = startFuncs [ periodIndex ] ( now , options ) ;
35
35
parsedDate = addFuncs [ periodIndex ] ( parsedDate , 1 ) ;
@@ -42,7 +42,7 @@ const parseHumanDate = function(input: string): Date | undefined {
42
42
const case1b : RegExp = new RegExp ( `next (${ dateNames . weekday } )` , 'gi' ) ;
43
43
if ( matchArray = case1b . exec ( input ) ) {
44
44
// console.log(matchArray);
45
- console . log ( 'case 1b: next <weekday>' ) ;
45
+ // console.log('case 1b: next <weekday>');
46
46
const weekdayIndex = getWeekdayIndex ( matchArray [ 1 ] ) ;
47
47
parsedDate = startOfWeek ( today ) ;
48
48
//parsedDate = datefns.addWeeks(parsedDate, 1);
@@ -56,7 +56,7 @@ const parseHumanDate = function(input: string): Date | undefined {
56
56
parsedDate = new Date ( ) ; // get fresh date and time
57
57
if ( matchArray = case2 . exec ( input ) ) {
58
58
// console.log(matchArray);
59
- console . log ( 'case 2: in <x> <period>' ) ;
59
+ // console.log('case 2: in <x> <period>');
60
60
const num : number = parseInt ( matchArray [ 1 ] ) ;
61
61
const periodIndex : number = periods . indexOf ( matchArray [ 2 ] ) ;
62
62
parsedDate = addFuncs [ periodIndex ] ( parsedDate , num ) ;
@@ -67,7 +67,7 @@ const parseHumanDate = function(input: string): Date | undefined {
67
67
// case 3: today/tonight/tomorrow/weekday
68
68
// case 3a: today/tonight/tomorrow
69
69
if ( input == 'today' || input == 'tomorrow' || input == 'tonight' ) {
70
- console . log ( 'case 3a: today/tonight/tomorrow' ) ;
70
+ // console.log('case 3a: today/tonight/tomorrow');
71
71
if ( input == 'tomorrow' ) {
72
72
parsedDate = addDays ( today , 1 ) ;
73
73
} else if ( input == 'tonight' ) {
@@ -82,7 +82,7 @@ const parseHumanDate = function(input: string): Date | undefined {
82
82
const case3b : RegExp = new RegExp ( `^\\s*${ dateNames . weekday } \\s*$` , 'gi' ) ;
83
83
if ( matchArray = case3b . exec ( input ) ) {
84
84
// console.log(matchArray);
85
- console . log ( 'case3b: <weekday>' ) ;
85
+ // console.log('case3b: <weekday>');
86
86
const weekdayIndex : number = getWeekdayIndex ( matchArray [ 0 ] ) ;
87
87
parsedDate = setDay ( today , weekdayIndex ) ;
88
88
// if past, get day in next week for same weekday
@@ -117,7 +117,7 @@ export const parseDate = function(input: string, format: string): Date {
117
117
format = format || 'yyyy-mm-dd HH:MM' ; // Default format
118
118
let humanDate : Date | undefined = parseHumanDate ( input ) ;
119
119
if ( humanDate ) { // successfully parsed as human date
120
- console . log ( 'human date:' , fnsFormat ( humanDate , 'PPPPp' ) ) ;
120
+ // console.log('human date:', fnsFormat(humanDate, 'PPPPp'));
121
121
return humanDate ;
122
122
}
123
123
let parts : Array < number > ;
0 commit comments