Java code to use Ical rrule and generate next recurrence date - icalendar

I need a java code snippet to parse ICal rrule and generate the next recurrence date.
There is a Java library specifically for parsing RRULEs called google-rfc-2445.
The following link contains an example using the library where you supply a start date along with an RRULE and it prints out the dates.
http://google-rfc-2445.googlecode.com/svn/trunk/README.html
But I don't want to use the google lib.

You can use ical4j: https://github.com/ical4j/ical4j
More specifically, you can use the Component.calculateRecurrenceSet() method

Related

Date and Time Validation Checking in freemarker

I would like to check the given date and time against the following formats.
Date -- {YYYYMMDD},
Time need to check with four formats -- {HHMM, or HHMMSS, or HHMMSSD, or HHMMSSDD}
Above date and time formats needs to be checked using freemarker,
How to check and validate in freemarker? ..
Please suggest
Validation (like input validation) is normally not done in templates. So if you parse strings with ?date(pattern)/?time(pattern), and the format doesn't match, the whole template terminates with error. If you just need to figure out which of those formats a string input is in, you could use the length (?length) and/or regular expressions (?matches(regexp)).

SOAP UI variables (e.g., date)

I am using SOAP UI Pro. I have a request from which this is an excerpt:
<ns2:OfficeType>
<ns2:OfficeTypeCode>M</ns2:OfficeTypeCode>
<ns2:EffectiveDate>2000-01-01</ns2:EffectiveDate>
<ns2:TerminationDate>9999-12-31</ns2:TerminationDate>
<ns2:IsPrimary>true</ns2:IsPrimary>
</ns2:OfficeType>
Instead of for instance, 2000-01-01, I want to use today (so for the day I am writing this it would be 2015-03-10. You may be reading on March 12 in which case it would be 2015-03-12, etc.). I could theoretically edit the SOAP request each time I send it out and replace the fields with the current date, but this is supposed to be automatic. I would like a say to say, instead of 2010-01-01 use something like $(Today'YYYY-MM-DD') (that is just an example probably nothing near the actual syntax).
Is there a way to get the current date placed into a SOAP UI message from SOAP UI Pro?
In SOAPUI you can use groovy code directly in your SOAP Request using the follow notation ${=groovy expression}, so in your case you can use ${=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date())} to get today date in yyyy-MM-dd format.
Directly in your test request you can use:
<ns2:OfficeType>
<ns2:OfficeTypeCode>M</ns2:OfficeTypeCode>
<ns2:EffectiveDate>${=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date())}</ns2:EffectiveDate>
<ns2:TerminationDate>9999-12-31</ns2:TerminationDate>
<ns2:IsPrimary>true</ns2:IsPrimary>
</ns2:OfficeType>
Hope this helps,
This will give you a nice UTC formated date/time:
<ns2:EffectiveDate>${=java.time.Instant.now().truncatedTo(java.time.temporal.ChronoUnit.SECONDS)}</ns2:EffectiveDate>
If you are using SoapUI Pro, then you may have the following script in TestRunListener.beforeRun Event
import java.text.SimpleDateFormat
def today = new Date()
def dateFormat = new SimpleDateFormat("yyyy-MM-dd")
def date = dateFormat.format(today)
log.info date
testRunner.testCase.setPropertyValue('DATE', date)
And in the request have
<ns2:EffectiveDate>${#TestCase#DATE}</ns2:EffectiveDate>
i.e., using the value DATE which was set in the beforeRun event.
Note: You can change the date format whatever you want, here it is used yyyy-MM-dd format as you mentioned in the question.

Robotframework: Getting date at runtime using Get Current Date, in specific format

I am using the Get Current Date keyword to return the date in the format year-month-day. I use this particular information to make sure that an account's created timestamp is correct in automated tests.
The issue is that the keyword is not recognised, my code should be correct (it should work and it should produce the date in the format I wish.
*** Keywords ***
Initialize Test Data
${DATE}= Get Current Date result_format=timestamp
${MYNUM}= faker.Random Int
Set Suite Variable ${MYNUM}
Set Suite Variable ${DATE}
Why do I get the error No keyword with name 'Get Current Date' found.?
Thanks in advance.
Does a keyword Get Current Date exist in standard RF lib? There is a builtin keyword called Get Time instead. Documentation explains how to format output. To use Get Current Date you need to import DateTime library first.
Update:
RF script sample which works for me:
*** Settings ***
Library DateTime
*** Test Cases ***
datatimetest
${d}= get time
log {d}
${d}= Get Current Date result_format=%Y-%m-%d
log {d}
${d} = Add Time To Date 2014-05-28 12:05:03.111 7 days
log {d}
Please remember that DateTime is a new library so in case you have old version of Robot Framework, you need to either install library or upgrade RF.
I'm using RF with Python and by default my IDE detects Python DateTime library.
Try to use the full path:
Library robot.libraries.DateTime
robot.libraries.DateTime.
You can also format the time as you like. See this answer. It offers format suggestions. You can use Python DateTime functions as in
${now} Evaluate '{dt.day}/{dt.month}/{dt.year}'.format(dt=datetime.datetime.now()) modules=datetime
Log ${now}
Log to Console now time 1: ${now}
${now} Evaluate '{dt:%A}, {dt:%B} {dt.day}, {dt.year}'.format(dt=datetime.datetime.now()) modules=datetime
Log ${now}
Log to Console now time 2: ${now}

How to get list of occurrence dates from iCalendar RRULE

I have the iCalendar file with RRULE for occurrences. How to get the list of dates on which the event will be occurring as per given start date and RRULE in the iCal file.
In Java, I want to write a method which should take start date and RRULE and return me the list of occurrence dates. Please help with simple solution or directions.
There is a Java library specifically for parsing RRULEs called google-rfc-2445.
The following link contains an example using the library where you supply a start date along with an RRULE and it prints out the dates.
http://google-rfc-2445.googlecode.com/svn/trunk/README.html
I do not have a chance to read README because of 404 - The requested URL /svn/trunk/README.html was not found on this server. If you have an example to show, please share it. I've found another solution lib-recur. lib-recur is shared via maven repository.

Custom Date Formatting in J2ME

I would like to format a J2ME Date object to only show the date part, not the date and time. What would be the easiest way? Would probably need to include an external library to do this.
java.util.Calendar has all the methods required to format a date output.