The MSPro Boomi Collection
About
Good Practices & Patterns
Good Practices & Patterns
  • Markus' Boomi Integration
  • Implementation Patterns
    • The Cache Challenge
      • The Get-Or-Create Use-Case
      • PropCache Scripts
    • State Management
      • Example Scenario
      • State-Management in general
      • State-Management Functionality
      • Technical Solutions
        • Boomi File-System Implementation
          • saveState
          • readState & fetchStates
    • Exception Handling
      • Exception vs Error
      • Basic Rules
        • Aggregating Exceptions
      • Exception Handling Pattern
        • User-Defined Exception Messages
        • Catch Exceptions
      • The pattern in practice
        • API Error Handling
          • Single Record Strategy
            • Single Record RES
          • Many Records Strategy (Array)
            • Many Records RES
        • Pre-Condition Check
    • SQL Patterns
      • Script Header
      • General Rules
        • Check using RowCount
        • Check if record exists
        • Pagination and Sorting
        • Parameter - Best Practices
        • Use JSON as a complex parameter
    • Process Patterns
      • Process Route Implementation Pattern
      • Sub-Process or Process Route
    • DateTime
      • The Boomi datetime dilemma
      • Database and Flow
      • Groovy
      • Data Hub
      • Get Current Date
    • Groovy Script Patterns
      • Dynamic Document Properties
      • Dynamic Process Properties
      • Documents
    • Array Elements to Documents
  • MSPro Services
    • Intermediate Storage
      • Example Processes
        • Docs 01 - Update and Create
          • sub.SampleData.Invoice
        • 02 - Upsert and Get
    • Render Templates
  • Tips
Powered by GitBook
On this page
  • Get UTC now
  • Log Datetime
  1. Implementation Patterns
  2. DateTime

Groovy

Get UTC now

println "-------------------------------------------------------------------"

import java.text.SimpleDateFormat

final SimpleDateFormat atomDefault = new SimpleDateFormat("yyyyMMdd HHmmss.SSS")
atomDefault.setTimeZone(TimeZone.getTimeZone("CET"))

final SimpleDateFormat utcISO = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
final SimpleDateFormat localISO = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS")
//utcISO.setTimeZone(TimeZone.getTimeZone("GMT"));

String utcDateS = utcISO.format( new Date())
println "UTC -now() as String: $utcDateS"

Date dt = utcISO.parse( utcDateS)
println "UTC -now() as Date  : $dt"
println "---"

String atomTimeS = atomDefault.format( new Date())
println "ATOM-now   () as String: $atomTimeS"
Date atomTimeUTC = atomDefault.parse( atomTimeS)
println "ATOM-nowUTC() as Date  : $atomTimeUTC"

// it does formatting, only, no time-zone shift!!!
// Take a datetime from UTC time-zone and format it without 'Z'
atomTimeS = localISO.format( atomTimeUTC)
println "ATOM-nowUTC() as String: $atomTimeS"

println "---"

String inS = "2023-07-31T14:00:00Z"
Date   inDt =utcISO.parse( inS)
println "String: $inS"
println "--> dateTime: $inDt"
String result = localISO.format( inDt)
println "--> dString w/o Z: $result"

PASS result to the DB profile as Date/Time

Format d.profile to json

import java.text.SimpleDateFormat

final SimpleDateFormat atomDefault = new SimpleDateFormat("yyyyMMdd HHmmss.SSS")
atomDefault.setTimeZone(TimeZone.getTimeZone("CET")) // simulate ATOM time-zone

// Simulate a d.Profile with Date/Type
Date atomDateTimeField = atomDefault.parse( "20230728 142051.525")
println atomDateTimeField                   // Fri Jul 28 12:20:51 UTC 2023

final SimpleDateFormat utcISO = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
utcISO.setTimeZone(TimeZone.getTimeZone("CET")) 	// put formatter on the same time-zone as atomDefault
println utcISO.format( atomDateTimeField)

Log Datetime

IN_S : Character
IN_DT: Date/Time

import com.boomi.execution.ExecutionUtil;
_logger = ExecutionUtil.getBaseLogger()
_logger.info('IN_S: ' + IN_S )
_logger.info('IN_DT:' + IN_DT)

Last updated 1 year ago