1
+ // TODO: momentjs is no longer supported. Replace with another date utility/practice. See https://momentjs.com/docs/#/-project-status/.
1
2
const moment = require ( 'moment' ) ;
2
3
3
- const convertDateToString = ( date , format = 'DD-MM-YYYY' ) => {
4
+ const convertDateToString = ( date , format = 'DD-MM-YYYY' , { locale } = { } ) => {
4
5
if ( ! date ) return '' ;
6
+ if ( locale ) setLocale ( locale ) ;
5
7
return moment . utc ( date ) . format ( format ) ;
6
8
} ;
7
9
8
- const convertStringToDate = ( date , format = 'DD-MM-YYYY' ) => {
10
+ const convertStringToDate = ( date , format = 'DD-MM-YYYY' , { locale } = { } ) => {
11
+ if ( locale ) setLocale ( locale ) ;
9
12
return moment . utc ( date , format ) . toDate ( ) ;
10
13
} ;
11
14
12
15
const convertStringFormatToAnotherFormat = (
13
16
date ,
14
17
fromFormat = 'DD-MM-YYYY' ,
15
- toFormat = 'MM-DD-YYYY'
18
+ toFormat = 'MM-DD-YYYY' ,
19
+ { locale } = { }
16
20
) => {
21
+ if ( locale ) setLocale ( locale ) ;
17
22
return moment . utc ( date , fromFormat ) . format ( toFormat ) ;
18
23
} ;
19
24
@@ -32,31 +37,13 @@ const checkDaysBetweenDates = (date, otherDate) => {
32
37
return Math . ceil ( hours / 24 ) ;
33
38
} ;
34
39
35
- const gitUpdatedDateToString = ( dateString , locale = 'default' ) => {
36
- const lc = ( pattern , string ) =>
37
- string . replace ( pattern , pattern . toLowerCase ( ) ) ;
38
- const timeZone = 'UTC' ;
39
- const options = { month : 'short' } ;
40
-
41
- const date = new Date ( dateString ) ;
42
- const month = date . toLocaleString ( locale , options ) ;
43
- const day = date . getDate ( ) ;
44
- const year = date . getFullYear ( ) ;
45
- const time = date
46
- . toLocaleTimeString ( locale , { timeZone : timeZone } )
47
- . replace ( / \s / g, ' ' ) ;
48
-
49
- const timeStamp = `${ month } ${ day } , ${ year } at ${ time } ${ timeZone } ` ;
50
-
51
- return lc ( 'PM' , lc ( 'AM' , timeStamp ) ) ;
52
- } ;
40
+ const setLocale = ( locale = 'en' ) => moment . locale ( locale ) ;
53
41
54
42
module . exports = {
55
43
convertDateToString,
56
44
convertStringToDate,
57
45
convertStringFormatToAnotherFormat,
58
46
isValidDate,
59
47
isAfterYear,
60
- checkDaysBetweenDates,
61
- gitUpdatedDateToString
48
+ checkDaysBetweenDates
62
49
} ;
0 commit comments