Skip to content
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

Functionalities to convert date time (in PT format) in total minutes/seconds #26

Merged
merged 6 commits into from
Apr 5, 2018

Conversation

Nimesh-Msys
Copy link
Contributor

For an example when time_str = 'PT1M60S' it will be either '2 mins' OR '120 seconds' in total.
time_in_minutes(time_str) OR time_in_seconds(time_str) will give above results respectively.

  • This may stretch up to hours/days/months even years

Significance: When a user inserts some random time interval while creating/updating a task (say in minutes; (65)) ,then during retrieving trigger's information, windows returns PT1M5S. Hence, he must be able to check this result as 65 mins again.

Signed-off-by: Nimesh Patni nimesh.patni@msystechnologies.com

…seconds.

eg, when time_str = PT1M60S it will be either 2 mins OR 120 seconds in total.
time_in_minutes(time_str) OR time_in_seconds(time_str) will give these result

* This may stretch up to hours/days/months even years

When a user inserts some random time interval while creating/updating a task (say in minutes; (65)) ,then during retrieving trigger's information, windows returns PT1M5S. Hence, he must be able to check this result as 65 mins again.

Signed-off-by: Nimesh Patni <nimesh.patni@msystechnologies.com>
module Windows
module TimeCalcHelper

DAY_OF_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
Copy link
Contributor

Choose a reason for hiding this comment

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

do we use the 0 index here? that feels like kind of a hack. Could we at least make that value nil and add a comment here as to why there are 13 months?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't use 0th index, but the structure of this array is maintained in a way that it returns actual no of days in a month (directly with month number), without any manipulation

eg, JAN(month No: 1) => DAY_OF_MONTH[1] => 31
Usage: @#L8:
(month == 2 && is_leap_year?(year)) ? 29 : DAY_OF_MONTH[month]

Also, I've kept this' 0' purposely. Keeping a 'nil' or 'a blank string' at first place could be prone to exceptions in calculations and hence it may require a conversion (to_i), which is an overhead.(Please let me know your views)

Have updated PR with comment in code explaining its significance.
Thank you


# Basic time variables
future_year = curr_time.year + dt_tm_hash[:year].to_i
future_mth = curr_time.month + dt_tm_hash[:month].to_i
Copy link
Contributor

Choose a reason for hiding this comment

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

can we call this future_month instead of future_mth since we use month in full everywhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have updated the variable name. Thank you

Signed-off-by: Nimesh Patni <nimesh.patni@msystechnologies.com>
Signed-off-by: Nimesh Patni <nimesh.patni@msystechnologies.com>
# Array with a 0 is defined to give actual result without
# any manipulation. eg, DAY_OF_MONTH[1] = 31
# 0(NUMBER) is kept to avoid exceptions during calculations
DAY_OF_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

Choose a reason for hiding this comment

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

probably rename this to DAYS_IN_A_MONTH?

Copy link
Contributor Author

@Nimesh-Msys Nimesh-Msys Mar 30, 2018

Choose a reason for hiding this comment

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

Renamed the variable as per review comment
Thank you

DAY_OF_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

# Returns no of days in a given month of a year
def day_in_month(month, year)

Choose a reason for hiding this comment

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

And this to get_days_in_a_month for clarity?

Copy link
Contributor Author

@Nimesh-Msys Nimesh-Msys Mar 30, 2018

Choose a reason for hiding this comment

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

As per ruby best practices, we should generally avoid using 'get_' and 'set_' in method names. It is a trivial technique that we often use in Java/C/C++.(Got this idea while working with Rubocop). Few reasons are listed here
Still, If it is needed for better understanding, will update the code accordingly.
Kindly let us know your views about this
Thank you

Copy link

@PrajaktaPurohit PrajaktaPurohit left a comment

Choose a reason for hiding this comment

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

I think it will be helpful to have some unit tests for the new Time calculations added.

@Nimesh-Msys
Copy link
Contributor Author

Working on rspecs for this module. Thanks

@Nimesh-Msys Nimesh-Msys changed the title Functionalities to convert date time (in PT format) in total minutes/seconds [In Progress]Functionalities to convert date time (in PT format) in total minutes/seconds Apr 2, 2018
@Nimesh-Msys Nimesh-Msys changed the title [In Progress]Functionalities to convert date time (in PT format) in total minutes/seconds Functionalities to convert date time (in PT format) in total minutes/seconds Apr 3, 2018
@btm btm merged commit 9da4c3c into chef:ole Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants