comparison libervia/backend/tools/common/date_utils.py @ 4185:c6d85c31a59f

plugin ad-hoc registration: Implement plugin to handle registration links: registration links are used in web frontend to allow registration with secret links when it's normally closed.
author Goffi <goffi@goffi.org>
date Sun, 10 Dec 2023 18:32:04 +0100
parents 4325a0f13b0f
children 0d7bb4df2343
comparison
equal deleted inserted replaced
4184:50c919dfe61b 4185:c6d85c31a59f
84 return int(value) 84 return int(value)
85 except ValueError: 85 except ValueError:
86 raise e 86 raise e
87 return calendar.timegm(dt.utctimetuple()) 87 return calendar.timegm(dt.utctimetuple())
88 88
89 def date_parse_ext(value, default_tz=TZ_UTC): 89 def date_parse_ext(value: str, default_tz: datetime.tzinfo=TZ_UTC) -> float:
90 """Extended date parse which accept relative date 90 """Extended date parse which accept relative date
91 91
92 @param value(unicode): date to parse, in any format supported by parser 92 @param value: date to parse, in any format supported by parser
93 and with the hability to specify X days/weeks/months/years in the past or future. 93 and with the hability to specify X days/weeks/months/years in the past or future.
94 Relative date are specified either with something like `[main_date] +1 week` 94 Relative date are specified either with something like `[main_date] +1 week`
95 or with something like `3 days ago`, and it is case insensitive. [main_date] is 95 or with something like `3 days ago`, and it is case insensitive. [main_date] is
96 a date parsable by parser, or empty to specify current date/time. 96 a date parsable by parser, or empty to specify current date/time.
97 "now" can also be used to specify current date/time. 97 "now" can also be used to specify current date/time.
98 @param default_tz(datetime.tzinfo): same as for date_parse 98 @param default_tz: same as for date_parse
99 @return (int): timestamp 99 @return: timestamp
100 """ 100 """
101 m = RELATIVE_RE.match(value) 101 m = RELATIVE_RE.match(value)
102 if m is None: 102 if m is None:
103 return date_parse(value, default_tz=default_tz) 103 return date_parse(value, default_tz=default_tz)
104 104