My adventure in learning Groovy Script for Cloud Integration (CI) – Part 3
Here I am just explaining the Importance of Groovy script in the Real time scenarios when we are dealing with Cloud Integration.
Groovy scripting is an integral and important feature of SAP Cloud Platform Integration (CPI). The goals of this repository are: Providing templates when you are implementing a new script. Easily finding Groovy functions related to the CPI topic at hand. Minimizing search engine time for common tasks.
In this blog I focused on Date functions using Java Script
Finding out Today’s Date
Date Formatting & Date Parsing
Changing one Date format to another Date format
Sometimes, we need to format date object into desired format. In Groovy, you can use format function to format date object. You can see a quick example below.
Date parsing is the operation of conversion date string to date object. You can simply parse date string to date object easily like below.
Adding number of days to the current date and subtracting number of days to the current date
The main advantage of the Groovy date extension is the doing arithmetic operations on date object. Let say that, you have a date and you want to find the date object which is 5 days after from current date and 10 days before the current date In order to do that, you can use following example.
In some cases, you may need to get year, month, date values separately from date objects, or you may need to set those fields in date objects separately. Subscript operators help us to get that specific values.
Converting Seconds time into complete Time Duration (Days, Hours and Minutes)
In some cases, you may need to convert seconds time in to complete duration for some particular Business requirements. The below example will help you how to get the seconds time in to number of days, number of hours and number of minutes.
Showing Current time into multiple Time Zones
In some cases, if you want to populate your current date according to Time Zones, the below example will help you to achieve the requirement.
How to add hours and minutes to current date
Convert a Unix Timestamp to Time
Unix Timestamp Example: 1651822834
Input = 1615204493000
Date operations are the operations that we used during software development, and it is really painful on converting dates from one format to another. In Groovy, these operations are very simplified, and you can easily perform date operations like applying arithmetic in Math. You can parse date string, format a date object, increment – decrement date, and apply subscript operators on date objects without using any third-party libraries.
Hope this document will help to beginners to understand CPI concept of Groovy Script.