Skip to content

Instantly share code, notes, and snippets.

@bardware
Created August 22, 2018 17:44
Show Gist options
  • Select an option

  • Save bardware/eac0fe4c7f03774eb35bf967c0ede9fc to your computer and use it in GitHub Desktop.

Select an option

Save bardware/eac0fe4c7f03774eb35bf967c0ede9fc to your computer and use it in GitHub Desktop.
Timezone list
<cfset oZoneId = createObject( "java", "java.time.ZoneId")>
<cfset oInstant = createObject( "java", "java.time.Instant")>
<cfset oTextStyle = createObject( "java", "java.time.format.TextStyle")>
<cfset oLocale = createObject( "java", "java.util.Locale").init( getLocale() )>
<cfset qryTZ = queryNew(
"offset,zone,region,displayfull,displayfullstdo,displaynarrow,displaynarrowstdo,displayshort,displayshortstdo,displayfulloffset,displayshortoffset",
"Integer,VarChar,VarChar,VarChar,VarChar,VarChar,VarChar,VarChar,VarChar,VarChar,VarChar"
)>
<cfset oIt = oZoneId.getAvailableZoneIds().Iterator()>
<cfoutput>
<cfloop condition="#oIt.hasNext()#">
<cfset strTz = oIt.next()>
<cfif listFindNoCase( "Africa,America,Asia,Atlantic,Australia,Europe,Indian,Pacific", ListGetAt( strTz, 1, "/" ) ) GT 0>
<cfset iOffset = oZoneId.of( strTz ).getRules().getStandardOffset( oInstant.now() ).getTotalSeconds()>
<cfset queryAddRow( qryTZ,
{
offset = iOffset,
zone = strTz,
region = ListGetAt( strTz, 1, "/" ),
displayfull = oZoneId.of( strTz ).getDisplayName( oTextStyle.FULL, oLocale ),
displayfullstdo = oZoneId.of( strTz ).getDisplayName( oTextStyle.FULL_STANDALONE, oLocale ),
displaynarrow = oZoneId.of( strTz ).getDisplayName( oTextStyle.NARROW, oLocale ),
displaynarrowstdo = oZoneId.of( strTz ).getDisplayName( oTextStyle.NARROW_STANDALONE, oLocale ),
displayshort = oZoneId.of( strTz ).getDisplayName( oTextStyle.SHORT, oLocale ),
displayshortstdo = oZoneId.of( strTz ).getDisplayName( oTextStyle.SHORT_STANDALONE, oLocale ),
displayfulloffset = oZoneId.of( strTz ).getDisplayName( oTextStyle.FULL, oLocale ) & " (UTC#iOffset LT 0 ? "-" : "+"##TimeFormat( CreateTimeSpan( 0, 0, 0, abs( iOffset ) ), "HH:mm" )#)",
displayshortoffset = oZoneId.of( strTz ).getDisplayName( oTextStyle.SHORT, oLocale ) & " (UTC#iOffset LT 0 ? "-" : "+"##TimeFormat( CreateTimeSpan( 0, 0, 0, abs( iOffset ) ), "HH:mm" )#)"
}
)>
</cfif>
</cfloop>
</cfoutput>
<cfquery name="qryTZOffset" dbtype="Query">
SELECT *
FROM qryTZ
ORDER BY offset DESC, [zone]
</cfquery>
<cfdump var="#qryTZOffset#" expand="false">
<cfquery name="qryTZDisp" dbtype="Query">
SELECT displayfulloffset, offset, count(*) anz
FROM qryTZ
GROUP BY displayfulloffset, offset
ORDER BY offset DESC, displayfulloffset
</cfquery>
<cfdump var="#qryTZDisp#" expand="true">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment