Skip to main content

to_dayjs

Function to_dayjs 

Source
pub fn to_dayjs(pattern: &str) -> Result<String>
Expand description

Translate a PHP pattern to Day.js tokens: Y y m n d j H G h g i s a A D l M F w v O P U, escaped literals and any non-letter. U needs Day.js’s advancedFormat plugin.

Day.js has no way to separate two tokens other than a character that prints, so two tokens that would run into a different one are rejected: nm would be MMM, the short month name. Put a character between them.

use php_dates::formats::to_dayjs;

assert_eq!(to_dayjs("d/m/Y H:i")?, "DD/MM/YYYY HH:mm");
assert_eq!(to_dayjs("Ymd")?, "YYYYMMDD");
assert!(to_dayjs("nm").is_err());

§Errors

Error::InvalidFormat for an empty pattern, a token Day.js cannot express, or two tokens that would be read as another one.