Skip to main content
Question

TCLCaller UTC to EST Conversion


Forum|alt.badge.img

All:

Can someone give me a slight push. I modified the code provided in the TCLCaller sample (provided in the Safe knowledge base - https://knowledge.safe.com/articles/769/converting-time-and-date-fields-to-local-timezones.html) to convert UTC date to EST. I have 5 dates I need to convert to EST and wanted to store them in separate attributes. I've attempted to create an array to return the 5 dates but no luck. I feel like I'm almost there. You will see some of the lines commented because I've been doing a variety of test scenarios trying to get my results.

Thanks in advance,

proc formatDate {} {

 

# this attribute matches the FME feature attribute

 

set QueryDate [FME_GetAttribute QueryDate]

 

set MROutageDate [FME_GetAttribute MostRecentOutage.OutageDate]

 

#set EventRepairDate [FME_GetAttribute EventOutage.RepairDate]

 

#set MRRepairDate [FME_GetAttribute MostRecentOutage.RepairDate]

 

#set EventOutageDate [FME_GetAttribute EventOutage.OutageDate]

 

 

#puts "date GMT $date"

 

# convert to clock seconds

 

set t_QueryDate [clock scan $QueryDate -format {%Y-%m-%dT%H:%M:%S%Z} -timezone :UTC ]

 

set t_MROutageDate [clock scan $MROutageDate -format {%Y-%m-%dT%H:%M:%S%Z} -timezone :UTC ]

 

#set t_EventRepairDate [clock scan $EventRepairDate -format {%Y-%m-%dT%H:%M:%S%Z} -timezone :UTC ]

 

#set t_MRRepairDate [clock scan $MRRepairDate -format {%Y-%m-%dT%H:%M:%S%Z} -timezone :UTC ]

 

#set t_EventOutageDate [clock scan $EventOutageDate -format {%Y-%m-%dT%H:%M:%S%Z} -timezone :UTC ]

 

 

#puts "t $t"

 

# switch to the new timezone and format the date

 

set dt_QueryDate [clock format $t_QueryDate -format {%Y%m%d%H%M%S} -timezone :EST ]

 

set dt_MROutageDate [clock format $t_MROutageDate -format {%Y%m%d%H%M%S} -timezone :EST ]

 

#set dt_EventRepairDate [clock format $t_EventRepairDate -format {%Y%m%d%H%M%S} -timezone :EST ]

 

#set dt_MRRepairDate [clock format $t_MRRepairDate -format {%Y%m%d%H%M%S} -timezone :EST ]

 

#set dt_EventOutageDate [clock format $t_EventOutageDate -format {%Y%m%d%H%M%S} -timezone :EST ]

 

 

#puts "date EST $datetime"

 

 

return $dt_QueryDate

 

return $dt_MROutageDate

 

#return $dt_EventRepairDate

 

#return $dt_MRRepairDate

 

#return $dt_EventOutageDate

 

}

3 replies

takashi
Influencer
  • April 17, 2018

Hi @bcrowley10, a Tcl procedure only returns a single value. If you defined two or more return statements, the first one would be executed but others do nothing. You can use the built-in function "FME_SetAttribute" to create multiple new attributes if necessary. See the Help on the TclCaller to learn more about FME build-in Tcl functions.

In addition, if you are using FME 2017.1 or later, you can use FME Date/Time Functions effectively, in order to manipulate timezone of datetime values.


fmelizard
Safer
Forum|alt.badge.img+18
  • Safer
  • April 17, 2018

Hi @bcrowley10 Just create the attributes on the feature with your Tcl script, e.g. FME_SetAttribute dt_QueryDate $dt_QueryDate Then expose dt_QueryDate and any other attributes you've created at the bottom of the TclCaller. Or if you want to make a list (similar to an array) then set it like:

FME_SetAttribute date_array{0}.date $dt_QueryDate

FME_SetAttribute date_array{1}.date $dt_MROutageDate

etc. and expose the attribute date_array{}


Forum|alt.badge.img
  • Author
  • April 18, 2018

Thank you Takashi for your response. I will use the date function. Not sure how I missed the

@TimeZoneSet function. Thank you Dan for your response as well.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings