Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Round time to nearest half hour using smart values in Jira Automation rule

ian.silver February 9, 2023

I have automation rules that automatically set the start/end time to {{now}} based on ticket transitions on change tickets.

This works exactly as intended.

For reporting and tracking purposes on the change calendar, I want to modify that time when I set it to the nearest half hour. (we would still track the actual timestamps via the change history.)

I've experimented with this but keep getting syntax errors:

{{now}.withMinute({{now}.minute}.divide(30).floor.multiply(30))}

Here's my thought process on how I expected this to work:

1. {now}.minute - extracts the number of minutes from the current time

2. .divide(30) produces a fractional amount >0 and <2

3. .floor returns either 0 or 1

4. .multiply(30) returns 0 or 30

5. .withMinute() gets the above result and sets the time to the current time, with minutes set to either :00 or :30

Could it be that .minute is not returning an integer that allows me to use arithmetic functions? Or even more basic, am I not able to access that attribute directly?

Is this even possible?

2 answers

1 accepted

1 vote
Answer accepted
Kian Stack Mumo Systems
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2023

@ian.silver

I approached it in a more simple way. I just pulled the minutes value from the date/time and used that inside of an if condition to choose how the date/time issue should be set.

 

Screen Shot 2023-02-09 at 1.02.28 PM.png

 

As you can see by my rule, anything logged within the first 15 minutes of the hours goes to the beginning over the hour. From minutes 16-44, it'll go to 30 minutes, and everything over 45 minutes will go to the start of the next hour. You'd also need to include conditions for 15 minutes and 45 minutes to make sure those go where you want as Jira doesn't include a "greater than or equal to" condition. I hope this helps!

Thanks,

Kian

ian.silver February 9, 2023

I like this Kian.  I will give it a try.

 

Thanks!

Ian

Kian Stack Mumo Systems
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2023

Based on your response on the other answer, you'll need to tweak the logic, but it should be pretty simple to do!

ian.silver February 9, 2023

I did just that.  My primary objective was to ensure consistent and clear visibility of change tickets in our change calendar.  When a change required only 5-10 minutes to execute, it appeared as a nearly invisible line on the calendar!

I've modified both of my automation rules for optimal results.  For the change start time, I use a simplified version of your suggestion: 

If the minutes are less than 31, set the time to  {{now.withMinute(0)}}

Otherwise set the time to {{now.withMinute(30)}}

This makes all our changes appear to start at the top or the bottom of the hour.

For the completion time, I needed to first make one additional check to ensure that short-duration changes still appear as a minimum 30-minute change:

{{Change completion date.diff(Change start date).minutes}}<30

If true, then {{Change completion date.plusMinutes(30)}}

Otherwise use the same if/then/else as for the start time rule.

Thanks for the guidance!

Like Kian Stack Mumo Systems likes this
Kian Stack Mumo Systems
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2023

I'm glad I could help! Have a great day!

0 votes
Vamsi Kandala
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2023

Hi @ian.silver

If I understand correctly, you want to round off the time to nearest half an hour in a sense if the current time is like

  • Between 11:00 AM to 11:30 AM, it will round off to 11:30 AM
  • Between 11:30 AM to 12:00 PM, it will round off to 12:00 PM

Is that what you are looking for?

In that case, you can use the smart values for date and time as mentioned in the article: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/ and set it accordingly in the automation rule.

If so, can you mention what the expected round-off time should be in the above scenarios?

Thanks,
Vamsi

ian.silver February 9, 2023

Hi Vamsi,

Thanks for your reply. You have correctly restated my objective.  

I probably should have said I was trying to round down to the nearest half-hour. (There is another complicating factor, but I think I can handle that once I get this functioning properly.)

If I could add a static value I could use 

{{[date].plus[Unit]([number])}}

The challenge has been that the number of minutes to be added/subtracted to the current time depends on what time it is.  I cannot simply add or subtract a fixed number of minutes. 

For example, if the actual start time is 02:04 AM, I need to subtract 04 minutes, but if the start time is 02:14, I need to subtract 14 minutes.

The formula I provided in my original post was attempting to address this by turning  any time between nn:00 and nn:30 to 0, and any time between nn:31 and nn:59 to 1, allowing me to then use a static value of 30 to modify the time (either 30*0, or 30*1)

If there is something in the article that you referenced that addresses this that I missed, can you please point that out to me?

 

Smiles,

Ian

Vamsi Kandala
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2023 edited

Hi @ian.silver

I am enclosing the screenshot here for your reference.

It is self-explanatory but still I will explain:

In the 'if' condition, I am checking if minutes are greater than 30, i.e. if the time is 2:37 PM, I am rounding it to 3:00 PM.

In the 'else' condition, I am checking if the minutes are less than 30, i.e. if the time is 2:15 PM, I am rounding it to 2:00 PM.

You can check and use the smart values I have used for your purpose.

Hope this helps.

Thanks,
Vamsi

automation time.png

The 'if' condition block

if block.png

Nilesh G April 11, 2024

Hi @Kian Stack Mumo Systems

As suggested by you, I am trying to set date/time picker field using following smart value. However, it shows syntax error "This smart value is invalid". Would you pls suggest if I am making any mistake here ?

{{now.jiraDate}}T{{now.hour}}:00:00

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, ace, atlassian community event, donation, girls who code, women in tech, malala fund, plan international, kudos, community badge, badge, atlassian badge, International Women’s month, International Women’s Day, women's month, women's day

10 for Change at Atlassian Community Events

Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!

Join an Atlassian Community Event!
AUG Leaders

Upcoming Jira Events