operation: datetime: It return the date time in the required format.#1339
operation: datetime: It return the date time in the required format.#1339gaurav879 wants to merge 2 commits into
Conversation
|
Hello @gaurav879 !! |
|
@programmer290399 made the changes. |
|
|
||
|
|
||
| @op(name="dffml.datetime", outputs=current_datetime) | ||
| def date_time(): |
There was a problem hiding this comment.
| def date_time(): | |
| def date_time_now() -> datetime.datetime: |
| date_time_format = str( | ||
| current_date + " " + current_time[0] + ":" + current_time[1] | ||
| ) | ||
| return date_time_format |
There was a problem hiding this comment.
- Let's use
datetime.strftime()instead ofstr
|
|
||
|
|
||
| @op(name="dffml.datetimeformat", outputs=date_time) | ||
| def date_time_format(): |
There was a problem hiding this comment.
| def date_time_format(): | |
| def date_time_format(datetime_obj: datetime.datetime, format: str) -> datetime.datetime: |
| return current_datetime | ||
|
|
||
|
|
||
| @op(name="dffml.datetimeformat", outputs=date_time) |
There was a problem hiding this comment.
| @op(name="dffml.datetimeformat", outputs=date_time) | |
| @op( | |
| name="dffml.datetimeformat", | |
| inputs={ | |
| "datetime_obj": date_time, | |
| "format": date_time, | |
| }, | |
| outputs={ | |
| "str": date_time_str, | |
| }, | |
| ) |
| date_time = Definition(name="date_time", primitive="generic") | ||
|
|
||
|
|
||
| @op(name="dffml.datetime", outputs=current_datetime) |
There was a problem hiding this comment.
| @op(name="dffml.datetime", outputs=current_datetime) | |
| @op( | |
| name="dffml.datetime.now", | |
| outputs={ | |
| "date_time_obj": date_time, | |
| }, | |
| ) |
| from ..df.base import op | ||
| from ..df.types import Definition | ||
|
|
||
| current_datetime = Definition(name="current_datetime", primitive="generic") |
There was a problem hiding this comment.
| current_datetime = Definition(name="current_datetime", primitive="generic") | |
| date_time_str = Definition(name="date_time_str", primitive="string") | |
| date_time_str_format = Definition(name="date_time_str_format", primitive="string", default="%Y-%m-%d %H:%M") |
| Current date and time. | ||
| """ | ||
| current_datetime = datetime.datetime.now() | ||
| return current_datetime |
There was a problem hiding this comment.
| return current_datetime | |
| return { | |
| "date_time_obj": current_datetime | |
| } |
There was a problem hiding this comment.
Related discusion on if we fix #1350 then we don't need this suggestion (can be done after merging this PR, could change back after 1350 is addressed)
There was a problem hiding this comment.
Example doctest as unittest is dffml/source/dataset/iris.py, consider using type()
| def date_time_format(): | ||
| """ | ||
| A function to modify date and time format. | ||
|
|
There was a problem hiding this comment.
Example here, pass in staticlly created datetime.datetime so that date is always the same
fixes #1327 . The function return date and time in the required format (yyyy-mm-dd hh:mm)