Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
NickSYYang
Active Participant
* * * * Update Start * * * *

Thanks great tips from emre.ozkan.

You can put timezone informatoin in the expression like below and then get local date and time without using script.

${date-with-timezone:now:Australia/Melbourne:yyyyMMddHHmmss}

I tested the above expression in CPI (build number 6.14.13) and it works perfectly!

* * * * Update End * * * *

In this blog, I am going to share how I came across time zone when I tried to use local time zone to be the target file name on Cloud Platform Integration (CPI).

Scenario


My requirement is that I want to create a file on receiver system and the name of this file is local time when file generated. Something like 20180228T2156.txt. So, I started exploring how CPI can help me to achieve this.

First I tried with following Camel's Simple expression in the File Name field inside SFTP adapter:
${date:now:ddMMyyyy'T'HHmm}

date:<command>:<pattern> for date formatting using the SimpleDateFormat patterns. Supported commands are: now for current timestamp. If you are not familiar with Camel's Simple expression language, please read through [1] and [2] in the references.

I thought this is the one to solve my problem, but after ran my integration flow. The generated file name is not what I expect. It is in UTC time but not local time. So, any other options in this expression I can set to have result in local time zone? I tried many different patterns in SimpleDateFormat, but still can't find a way to get what I want.



My next trying is to use groovy script to generate the local date time string for the file name. Below small code snippet helps me to generate local date and time and it's correct when time zone is in day light saving. I save the formatted string into message header for later used in SFTP channel configuration.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import static java.util.Calendar.*;
def Message processData(Message message) {
def localTimeZone = TimeZone.getTimeZone('Australia/Melbourne');
def cal = Calendar.instance;
def date = cal.time;
def dateFormat = 'ddMMyyyy\'T\'HHmm';
//Header
message.setHeader("CamelFileName", date.format(dateFormat, localTimeZone) + '.csv');
return message;
}

 

In SFTP adapter Target tab, I enter ${header.CamelFileName} in File Name field to retrieve the value I save in the script. All in the end I get my desired result. Now, it's much better than using UTC time.




References


[1] Get to know Camel’s Simple expression language in HCI by Morten Wittrock

[2] Apache Camel SimpleLanguage JavaAPI

 
1 Comment
Labels in this area