Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

operation: datetime: It return the date time in the required format. #1339

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
39 changes: 39 additions & 0 deletions dffml/operation/datetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import datetime
from ..df.base import op
from ..df.types import Definition

current_datetime = Definition(name="current_datetime", primitive="generic")
Copy link

@johnandersen777 johnandersen777 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")

date_time = Definition(name="date_time", primitive="generic")


@op(name="dffml.datetime", outputs=current_datetime)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@op(name="dffml.datetime", outputs=current_datetime)
@op(
name="dffml.datetime.now",
outputs={
"date_time_obj": date_time,
},
)

def date_time():
Copy link

@johnandersen777 johnandersen777 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def date_time():
def date_time_now() -> datetime.datetime:

"""
A function to generate current date and time.

Parameters
----------
output:
Current date and time.
"""
current_datetime = datetime.datetime.now()
return current_datetime

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return current_datetime
return {
"date_time_obj": current_datetime
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example doctest as unittest is dffml/source/dataset/iris.py, consider using type()



@op(name="dffml.datetimeformat", outputs=date_time)
Copy link

@johnandersen777 johnandersen777 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@op(name="dffml.datetimeformat", outputs=date_time)
@op(
name="dffml.datetimeformat",
inputs={
"datetime_obj": date_time,
"format": date_time,
},
outputs={
"str": date_time_str,
},
)

def date_time_format():
Copy link

@johnandersen777 johnandersen777 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def date_time_format():
def date_time_format(datetime_obj: datetime.datetime, format: str) -> datetime.datetime:

"""
A function to modify date and time format.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example here, pass in staticlly created datetime.datetime so that date is always the same

Parameters
----------
output:
Current date and time in yyyy-mm-dd hh:mm (24h)format.
"""
currentDateTime = date_time()
current_date = str(currentDateTime).split(" ")[0]
current_time = str(currentDateTime).split(" ")[1].split(".")[0].split(":")
date_time_format = str(
current_date + " " + current_time[0] + ":" + current_time[1]
)
return date_time_format

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.