@@ -36,16 +36,22 @@ export const dateTokens = [
36
36
* Format a date
37
37
* @param {string } string - ISO 8601 date
38
38
* @param {string } tokens - Tokenised date format
39
- * @param {string } [locale] - Locale name
40
- * @param {import("date-fns-tz").OptionsWithTZ } [options] - Options
39
+ * @param {object } [options] - Options
40
+ * @param {string } [options.locale] - Locale
41
+ * @param {string } [options.timeZone] - Time zone
41
42
* @returns {string } Formatted date
42
43
*/
43
- export const formatDate = ( string , tokens , locale , options = { } ) => {
44
- locale = String ( locale || "en" ) . replace ( "-" , "" ) ;
45
- options . locale = locales [ locale ] ;
44
+ export const formatDate = ( string , tokens , options = { } ) => {
45
+ const formattedLocale = String ( options . locale || "en" ) . replace ( "-" , "" ) ;
46
+
47
+ // Convert options object to options expected for `FormatOptionsWithTZ`
48
+ const formatOptions = {
49
+ ...options ,
50
+ ...( options . locale && { locale : locales [ formattedLocale ] } ) ,
51
+ } ;
46
52
47
53
const date = string === "now" ? new Date ( ) : parseISO ( string ) ;
48
- const dateTime = format ( date , tokens , options ) ;
54
+ const dateTime = format ( date , tokens , formatOptions ) ;
49
55
return dateTime ;
50
56
} ;
51
57
0 commit comments