#!#! #! #!#! #!#! #!#! #!#! #!#! #!#! #!

FME_Server_Date_Format_Converter.fmw

2015 Safe Software


The "email_publisher_received" attribute contains a date which looks like:


Fri Jan 10 16:32:45 GMT-06:00 2014


This is an example on how to convert it to the standard FME Date Format for easier use within FME:


20140110163245


" POSITION="-102.005 -1141" TOP_LEFT="-102.005 -1141" BOTTOM_RIGHT="647.995 -1191" BOUNDING_RECT="-102.005 -1141 750 50" ORDER="5e+14" FOLLOW_ANCHOR="true" INFO_NODE="false" COLOUR="1,1,0.784314,0.192157" SIZE_POLICY="10" COMMENT_TYPE="REGULAR" ANCHORED_NODE="0">
#!

Convert it to FME Date Format

" POSITION="1325.99 -737" TOP_LEFT="1325.99 -737" BOTTOM_RIGHT="1325.99 -737" BOUNDING_RECT="1325.99 -737 0 -0" ORDER="5e+14" FOLLOW_ANCHOR="true" INFO_NODE="false" COLOUR="1,1,0.784314,0.192157" SIZE_POLICY="8" COMMENT_TYPE="REGULAR" ANCHORED_NODE="10">
#!
#! #!#! #!#!#! #! #!#!#!#!#!#!#!#!#!#!#!#!#! #!#!#!#!#!#!#!#!#!#!#!#!#!#!#! #!#!#!#!#!#!#!#!#!#!#!#!#! #!#!#!#!#!#!#!#!#!#!#!#!#!#! #!#!#!#!#! #!#! #!#! #!#! #!#!
#!#!start_header#!start_wb_header reader_type null reader_keyword null_source null_source_dataset null writer_type null writer_keyword null_dest null_dest_dataset null#!end_wb_header#!end_header log_filename“$(fme_mf_dir)date_format_converter.log”log_append no log_max_features 200 log_max_recorded_features 200 log_max_precision yes fme_reproprex_engine fme fme_implicit_csmap_reproimper_mode auto fme_geometry_handling增强fme_stroke_max_deviation 0 log_filter_mask -1# --------------------------------------------------------------------- multi_reader_continue_on_reader_failure no#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- tcl2 proc creator_coordsysremover {} {global fme_coordsys;设置fme_coordsys {}; } MACRO Creator_XML NOT_ACTIVATED MACRO Creator_CLASSIC NOT_ACTIVATED MACRO Creator_2D3D 2D_GEOMETRY MACRO Creator_COORDS INCLUDE [ if { {Geometry Object} == {Geometry Object} } { puts {MACRO Creator_XML *} } ] INCLUDE [ if { {Geometry Object} == {2D Coordinate List} } { puts {MACRO Creator_2D3D 2D_GEOMETRY}; puts {MACRO Creator_CLASSIC *} } ] INCLUDE [ if { {Geometry Object} == {3D Coordinate List} } { puts {MACRO Creator_2D3D 3D_GEOMETRY}; puts {MACRO Creator_CLASSIC *} } ] INCLUDE [ if { {Geometry Object} == {2D Min/Max Box} } { set comment { We need to turn the COORDS which are minX minY maxX maxY into a full polygon list of coordinates }; set splitCoords [split [string trim { }]]; if { [llength $splitCoords] > 4} { set trimmedCoords {}; foreach item $splitCoords { if { $item != {} } {lappend trimmedCoords $item} }; set splitCoords $trimmedCoords; }; if { [llength $splitCoords] != 4 } { error {Creator: Coordinate list is expected to be a space delimited list of four numbers as 'minx miny maxx maxy' - ` ' is invalid}; }; set minX [lindex $splitCoords 0]; set minY [lindex $splitCoords 1]; set maxX [lindex $splitCoords 2]; set maxY [lindex $splitCoords 3]; puts "MACRO Creator_COORDS $minX $minY $minX $maxY $maxX $maxY $maxX $minY $minX $minY"; puts {MACRO Creator_2D3D 2D_GEOMETRY}; puts {MACRO Creator_CLASSIC *} } ] FACTORY_DEF $(Creator_XML) CreationFactory FACTORY_NAME Creator_XML_Creator CREATE_AT_END no OUTPUT FEATURE_TYPE _____CREATED______ @Geometry(FROM_ENCODED_STRING, ?XML. version= 1.0 encoding= US_ASCII standalone= ? geometry 尺寸= 2 null geometry (美元)FACTORY_DEF Creator_CLASSIC) CreationFactory FACTORY_NAME Creator_CLASSIC_Creator $(Creator_2D3D) $(Creator_COORDS) CREATE_AT_END no OUTPUT FEATURE_TYPE _____CREATED______ FACTORY_DEF * TeeFactory FACTORY_NAME Creator_Cloner INPUT FEATURE_TYPE _____CREATED______ NUMBER_OF_COPIES 1 COPY_NUMBER_ATTRIBUTE "_creation_instance" OUTPUT FEATURE_TYPE Creator_CREATED @Tcl2(Creator_CoordSysRemover) @CoordSys() fme_feature_type Creator # ------------------------------------------------------------------------- FACTORY_DEF * AttrSetFactory FACTORY_NAME AttributeCreator ATTRSET_CREATE_DIRECTIVES _PROPAGATE_MISSING_FDIV INPUT FEATURE_TYPE Creator_CREATED ATTR date Fri Jan 10 16:32:45 GMT-06:00 2014输出输出功能_type attributecreator_output#------------------------------------------------------------------------------------------------------- TCL2 procateDement_Formatter {InvalidValue} {Set DateFormat {FME日期/时间(%Y%M%D.%h%m%s)};if {[string compare $ dateformat {fme日期/时间(%y%m%d%h%m%s)}] == 0} {set dateformat {%y%m%d%h%m%s};} elsef {[string compare $ dateformat {fme日期(%y%m%d)}] == 0} {set dateformat {%y%m%d};} elsef {[string compare $ dateformat {fme时间(%h%m%s)}] == 0} {set dateformat {%h%m%s};} elsef {[string compare $ dateformat {iso日期(%y-%m%%d)}] == 0} {set dateformat {%y-%m%d};elsef {[string compare $ dateformat {iso dateTime(%y-%m - %dt%h:%m:%s)}] == 0} {led dateformat {%y-%m%dt%h:%小姐};elsef {[string compare $ dateformat {iso time(%h:%m:%s)}] == 0} {set dateformat {%h:%m:%s};} elsef {[string compare $ dateformat {locale date(%c)}] == 0} {set dateformat {%c};}; set attrs [split {date} {,}]; foreach attr $attrs { set date [string trim [FME_GetAttribute $attr]]; set comment { Ignore the millisecond part }; regexp {^[^.]*} $date date; set dateLen [string length $date]; set srcfmt {}; if {{%a %b %d %H:%M:%S GMT-06:00 %Y} != {FME_AUTOMATIC}} { set srcfmt {%a %b %d %H:%M:%S GMT-06:00 %Y}; }; if {$dateLen > 0} { if {[string length $srcfmt] == 0} { set attrFull $attr; append attrFull .full; set fullDate [FME_GetAttribute $attrFull]; if { [string compare -length $dateLen $date $fullDate] == 0 } { set extra [string range $fullDate $dateLen end]000000; set date [string range \"$date$extra\" 0 13]; set dateLen 14 }; if {($dateLen == 14) && [regexp {^[0-9]*$} $date]} { set srcfmt %Y%m%d%H%M%S; }; }; }; set sourceFormatOpt {}; if {[string length $srcfmt] > 0} { set sourceFormatOpt \"-format {$srcfmt}\"; }; if { (0 == $dateLen) || [catch { set seconds [eval clock scan "{$date}" $sourceFormatOpt]; FME_SetAttribute $attr [clock format $seconds -format $dateFormat]; }] } { if { $invalidValue == {FME_NULL_VALUE} } { FME_SetAttributeNull $attr; } elseif { $invalidValue != {_FME_NO_OP_} } { FME_SetAttribute $attr [FME_DecodeText $invalidValue]; }; }; }; } FACTORY_DEF * TeeFactory FACTORY_NAME DateFormatter INPUT FEATURE_TYPE AttributeCreator_OUTPUT OUTPUT FEATURE_TYPE DateFormatter_OUTPUT @Tcl2("DateFormatter_formatter {_FME_NO_OP_}") # ------------------------------------------------------------------------- FACTORY_DEF * TeeFactory FACTORY_NAME DateFormatter_Output_Logger INPUT FEATURE_TYPE DateFormatter_OUTPUT OUTPUT FEATURE_TYPE DateFormatter_Output_LOGGED @Log("DateFormatter_Output: Feature is:","20","20") @FeatureType(DateFormatter_Output_LOGGED) FACTORY_DEF * TeeFactory FACTORY_NAME "DateFormatter_Output LOGGED Output Nuker" INPUT FEATURE_TYPE DateFormatter_Output_LOGGED # ------------------------------------------------------------------------- FACTORY_DEF * RoutingFactory FACTORY_NAME "Destination Feature Type Routing Correlator" INPUT FEATURE_TYPE * OUTPUT ROUTED FEATURE_TYPE * @FeatureType(ENCODED,@Value(__wb_out_feat_type__)) @RemoveAttributes(__wb_out_feat_type__) OUTPUT NOT_ROUTED FEATURE_TYPE __nuke_me__ @Tcl2("FME_StatMessage 818059 [FME_GetAttribute fme_template_feature_type] 818060 818061 fme_warn") # ------------------------------------------------------------------------- FACTORY_DEF * TeeFactory FACTORY_NAME "Final Output Nuker" INPUT FEATURE_TYPE __nuke_me__