groovy code for date and time transfer


def String DateTransfer(String arg1){

 // Define the input and output date formats

    SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")

    SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMdd")

    

    // Parse the input date string to a Date object

    Date date = inputFormat.parse(arg1)

    

    // Format the Date object to the desired output format

    String outputDate = outputFormat.format(date)

    

    return outputDate

}

import com.sap.it.api.mapping.*;

import java.text.SimpleDateFormat


def String TimeTransfer(String arg1){

 // Define the input and output date formats

    SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")

    SimpleDateFormat outputFormat = new SimpleDateFormat("HHmmss")

    

    // Parse the input date string to a Date object

    Date date = inputFormat.parse(arg1)

    

    // Format the Date object to the desired output format

    String outputDate = outputFormat.format(date)

    

    return outputDate

}


-----------

concate string.

def void customFunc(String[] input, Output output, MappingContext context) {

    if (input != null && input.length > 0) {

        // Initialize an empty string to accumulate the concatenated values

        def result = ""


        // Iterate through the input array

        for (int i = 0; i < input.length; i++) {

            // Append each element of the array to the result string, separated by a semicolon

            result += input[i]

            if (i < input.length - 1) {

                result += ";"

            }

        }


        // Add the concatenated string to the output

        output.addValue(result)

    }

}

------------

def void customFunc(String[] input, Output output, MappingContext context) {

if (input != null && input.length > 0) {

boolean found = false
// Iterate through the input array using a for loop
for (int i = 0; i < input.length; i++) {
// Check if the item equals 4
if (input[i].toInteger() == 4) {
found = true
break
}
}
// Add "1" to the output if any item equals 4
if (found) {
output.addValue("1")
} else {
output.addValue("")
}
} else {
// If input is null or empty, add an empty value to the output
output.addValue("")
}
}

--------

def void customFunc(String[] input, Output output, MappingContext context) {

if (input != null && input.length > 0) {

boolean found = false
// Iterate through the input array using a for loop
for (int i = 0; i < input.length; i++) {
// Check if the item equals 4
if (input[i].toInteger() == 4) {
found = true
break
}
}
// Add "1" to the output if any item equals 4
if (found) {
output.addValue("1")
} else {
output.addValue("")
}
} else {
// If input is null or empty, add an empty value to the output
output.addValue("")
}
}



----

import com.sap.gateway.ip.core.customdev.util.Message;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.TimeZone;

def Message processData(Message message) {
    // Get properties from the message
    def map = message.getProperties();

    // Assuming the input timestamp is stored in properties named "Date" and "Time"
    def time = map.url("Time");
    def date = map.get("Date");
    def datetime = date + time;

    // Define the input and output date formats
    SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");

    // Parse the input timestamp
    Date parsedDate = inputFormat.parse(datetime);

    // Set the time zone to UTC+2 (Central European Summer Time)
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(parsedDate);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC+2"));

    // Format the date to the target format
    String formattedDate = outputFormat.format(calendar.getTime());

    // Add the formatted date to the properties
    map.put("formattedDate", formattedDate);

    // Update the message properties
    message.setProperties(map);

    return message;
}

----

import com.sap.gateway.ip.core.customdev.util.Message;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.TimeZone;

def Message processData(Message message) {
    // Get properties from the message
    def map = message.getProperties();

    // Assuming the input timestamp is stored in properties named "Date" and "Time"
    def time = map.get("Time");
    def date = map.get("Date");
    def datetime = date + time;

    // Define the input and output date formats
    SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");

    // Parse the input timestamp
    Date parsedDate = inputFormat.parse(datetime);

    // Set the time zone to UTC+2 (Central European Summer Time)
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(parsedDate);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC+2"));

    // Format the date to the target format
    String formattedDate = outputFormat.format(calendar.getTime());

    // Add the formatted date to the properties
    map.put("formattedDate", formattedDate);

    // Update the message properties
    message.setProperties(map);

    return message;
}


=${property.comp}&flt=LASTMODTIME=="${property.formattedDate}"&TYPE==SELLER;extUniqueCode!=(NULL)09:31 PM

Popular posts from this blog

pss book : శ్రీకృష్ణుడు దేవుడా, భగవంతుడా completed , second review needed. 26th April 2024

pss book: గురు ప్రార్థనామంజరి . completed 21st july 2024

pss book: కధల జ్ఞానము read review pending. 25th june 2024