Skip to content

CDK: improve day_delta macro and MinMaxDatetime component #22400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ def get_datetime(self, config, **additional_options) -> dt.datetime:
time = self._parser.parse(str(self.datetime.eval(config, **additional_options)), datetime_format, self.timezone)

if self.min_datetime:
min_time = self._parser.parse(str(self.min_datetime.eval(config, **additional_options)), datetime_format, self.timezone)
time = max(time, min_time)
min_time = str(self.min_datetime.eval(config, **additional_options))
if min_time:
min_time = self._parser.parse(min_time, datetime_format, self.timezone)
time = max(time, min_time)
if self.max_datetime:
max_time = self._parser.parse(str(self.max_datetime.eval(config, **additional_options)), datetime_format, self.timezone)
time = min(time, max_time)
max_time = str(self.max_datetime.eval(config, **additional_options))
if max_time:
max_time = self._parser.parse(max_time, datetime_format, self.timezone)
time = min(time, max_time)
return time

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def max(*args):
return builtins.max(*args)


def day_delta(num_days: int) -> str:
def day_delta(num_days: int, format: str = "%Y-%m-%dT%H:%M:%S.%f%z") -> str:
"""
Returns datetime of now() + num_days

Expand All @@ -93,7 +93,7 @@ def day_delta(num_days: int) -> str:
:param num_days: number of days to add to current date time
:return: datetime formatted as RFC3339
"""
return (datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=num_days)).strftime("%Y-%m-%dT%H:%M:%S.%f%z")
return (datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=num_days)).strftime(format)


def format_datetime(dt: Union[str, datetime.datetime], format: str):
Expand Down