Maybe this is something you can use to calculate minutes, hours, days, month years (seconds I did not need for my purpose): I created this keyword function for an outsystems specific datepicker to calculate based on a datetime value.
Calling code in testscript
String strDateTimenow
strDatenow = ‘20181226’
strTimenow = ‘05:32’
//concatenate the value as i
strDateTimenow = strDatenow + ’ ’ + strTimenow
String strDatenew = ‘’
String strTimenew = ‘’
String strDateTimenew
//Call the custom function to calculate the dates
strDateTimenew = CustomKeywords.‘utility.keywords.ChangeDates.changedatetime’(5, 30, 0, 0, 0, strDateTimenow)
// parameters
// 1. minutes – int
// 2. hours – int
// 3 days – int
// 4 months – int
// 5 years – int
// datetime you just entered and concatenated, make sure the simeple date format of the customfunction
// in this case “yyyyMMdd HH:mm”
package utility.keywords
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords
import internal.GlobalVariable
import java.text.SimpleDateFormat
import MobileBuiltInKeywords as Mobile
import WSBuiltInKeywords as WS
import WebUiBuiltInKeywords as WebUI
import org.openqa.selenium.interactions.Action
import org.openqa.selenium.interactions.Actions
import org.openqa.selenium.WebDriver
import groovy.time.TimeCategory
import com.kms.katalon.core.logging.KeywordLogger
import java.util.Date
public class ChangeDates {
private def Today
@Keyword
def changedatetime(int inp_MinutefromToday, int inp_HourfromToday, int inp_DatefromToday, int inp_MonthfromToday,int inp_YearfromToday,String strDatenowfromDatePicker){
String newDate = strDatenowfromDatePicker
def Todayd = new SimpleDateFormat("yyyyMMdd HH:mm")
Date Today = Todayd.parse(newDate)
use (groovy.time.TimeCategory){
// KeywordLogger log = new KeywordLogger()
//def today = input.parse("MM-dd-yyyy", startTime)
Date out_DatefromToday = Today
out_DatefromToday = Today + inp_MinutefromToday.minutes + inp_HourfromToday.hours + inp_DatefromToday.days + inp_MonthfromToday.months + inp_YearfromToday.years
System.out.println(out_DatefromToday)
String Currentdate = out_DatefromToday.toString()
def Currentdateparse = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy",Locale.ENGLISH)
def CurrentDateAdjusted = Currentdateparse.parse(Currentdate)
System.out.println(CurrentDateAdjusted)
def sdff = new SimpleDateFormat("yyyyMMdd HH:mm")
def frmDate = sdff.format(CurrentDateAdjusted); // Handle the ParseException here
return frmDate
}
}
}
on returning of the function you can substring the datenew and timenew
strDatenew = strDateTimenew.substring(0,8)
strTimenew = strDateTimenew.substring(9,14)
System.out.println(strDateTimenew)
System.out.println(strDatenew)
System.out.println(strTimenew)
good luck