Include optional default value in strptime (#26667)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
The00Dustin 2023-03-20 14:56:27 -04:00 committed by GitHub
parent 3ce6302ede
commit 7a99b47309
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -510,7 +510,7 @@ For example, if you wanted to select a field from `trigger` in an automation bas
- `as_datetime()` converts a string containing a timestamp, or valid UNIX timestamp, to a datetime object.
- `as_timestamp(value, default)` converts datetime object or string to UNIX timestamp. If that fails, returns the `default` value, or if omitted raises an error. This function can also be used as a filter.
- `as_local()` converts datetime object to local time. This function can also be used as a filter.
- `strptime(string, format)` parses a string based on a [format](https://docs.python.org/3.8/library/datetime.html#strftime-and-strptime-behavior) and returns a datetime object. If that fails, returns the `default` value, or if omitted raises an error.
- `strptime(string, format, default)` parses a string based on a [format](https://docs.python.org/3.10/library/datetime.html#strftime-and-strptime-behavior) and returns a datetime object. If that fails, it returns the `default` value or, if omitted, raises an error.
- `relative_time` converts datetime object to its human-friendly "age" string. The age can be in second, minute, hour, day, month or year (but only the biggest unit is considered, e.g., if it's 2 days and 3 hours, "2 days" will be returned). Note that it only works for dates _in the past_.
- `timedelta` returns a timedelta object and accepts the same arguments as the Python `datetime.timedelta` function -- days, seconds, microseconds, milliseconds, minutes, hours, weeks.