Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increment time by 10 minute intervals

Tags:

groovy

soapui

For a certain date (this is a hard coded date), I want to increment through the time for LastModifiedTimeFrom and LastModifiedTimeTo by 10 minutes each time.

I have tried the below but it is not performing the increment and I am not sure why?

Date d = Date.parse("HH:mm:ss", "00:00:00")
Calendar c = Calendar.getInstance()
c.setTime(d)

c.add(MINUTE, 10)
assert c.time == "00:10:00"

c.add(MINUTE, 10)
assert c.time == "00:20:00"

c.add(MINUTE, 10)
assert c.time == "00:30:00"
like image 748
BruceyBandit Avatar asked Feb 03 '17 09:02

BruceyBandit


People also ask

How do you increment time?

For adding time with 20 minutes increments:Enter formula =A1+TIME(0,20,0) into the Formula Bar, and then press the Ctrl + Enter key simultaneously.

How do I create a time interval in Excel?

Another simple technique to calculate the duration between two times in Excel is using the TEXT function: Calculate hours between two times: =TEXT(B2-A2, "h") Return hours and minutes between 2 times: =TEXT(B2-A2, "h:mm") Return hours, minutes and seconds between 2 times: =TEXT(B2-A2, "h:mm:ss")


1 Answers

I would recommend a combo approach of using some Groovy syntactic sugar and the verbose, but ever-reliable Java Calendar. With the code below, you should be able to parse in a date and start adding 10 minutes to it, checking it as you go along.

import java.util.Calendar
import static java.util.Calendar.*

Date d = Date.parse("HH:mm:ss", "00:00:00")
Calendar c = Calendar.getInstance()
c.setTime(d)

c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:10:00"

c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:20:00"

c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:30:00"
like image 124
rockympls Avatar answered Oct 04 '22 13:10

rockympls