Open Subha opened 3 years ago
In dayjs the format 'LT'
translates to 'h:mm A'
and 'A'
allows for 'pm', 'PM', 'am' or 'AM' but mot for 'a' or 'p' alone; therefore '3p' does not match neither 'LT'
nor 'h a'
(you see the extra space).
And then you get
'ha'
(no space between the 'h' and the 'a'!).import CustomParseFormat from "dayjs/plugin/customParseFormat";
import advancedFormat from "dayjs/plugin/advancedFormat";
dayjs.extend(customParseFormat)
dayjs.extend(advancedFormat)
dayjs('3pm', 'ha').format('LT'); // result 3:00 PM
dayjs('3:03 PM', 'LT').format('LT'); // result 3:03 PM
Describe the bug Replaced our application from moment to use dayjs and facing issues with our Timepicker.
while parsing this string to time, had to pass the format as array of strings unlike Moment but still we are not getting the expected result.
Plugins used: import CustomParseFormat from "dayjs/plugin/customParseFormat"; import advancedFormat from "dayjs/plugin/advancedFormat";
Current Behavior dayjs('3p', ['LT', 'h:mm', 'hh', 'h a', 'h']).format('LT'); // result 3.00 AM dayjs('3:03 PM', ['LT', 'h:mm', 'hh', 'h a', 'h']).format('LT'); // result 3.03 AM
Expected behavior
When 3p is passed expected to return 3:00 PM
Match moment api and pass same format.
moment('3p', 'LT').format('LT'); // result 3:00 PM moment('3:03 pm', 'LT').format('LT'); // 3:03PM
Information