#set( $lead = { "tzstring" : "America/Los_Angeles" } ) ---- #set( $dateOptions = { "timezones" : { "userout" : $lead.tzstring }, "dayParts" : [ { "name" : "Wee Hours", "min" : 00, "max" : 06 }, { "name" : "Morning", "min" : 07, "max" : 11 }, { "name" : "Afternoon", "min" : 12, "max" : 17 }, { "name" : "Early Evening", "min" : 18, "max" : 19 }, { "name" : "Night", "min" : 20, "max" : 21 }, { "name" : "Late Night", "min" : 22, "max" : 23 } ] } ) #set( $dtHere = $date.getCalendar() ) #set( $tmp = $dtHere.setTimeZone( $date.getTimeZone().getTimeZone($dateOptions.timezones.userout) ) ) #set( $hourThere = $dtHere.get($field.in($dtHere).HOUR_OF_DAY) ) #foreach( $part in $dateOptions.dayParts ) #if( $part.min <= $hourThere && $hourThere <= $part.max ) #set( $dayPart = $part.name ) #end #end Good ${dayPart}, Lead-O! As Nicholas and I both noted, you need to have the lead's timezone name on the lead. That's "America/New_York", "America/Los_Angeles", etc. or (not recommended) the static daylight-aware offsets like "EST5EDT". Note that "EST" is not a timezone you should be storing on a lead, and "PST" isn't a valid timezone at all. This is a frequent and aggravating mistake that people make (and which they're encouraged to make by bad tutorials). You need to use a zone that is daylight-aware. If you say someone is in EST, that means they're in EST all year round. Not good! In the code above, the timezone is stored in the $lead.tzstring field -- obviously change the name to whatever field you're using after checking it off on the right-hand-side of Script Editor. The dayParts array should be self-explanatory: set up stop and start hours (00-23) for each named part of the day. You may want to have a coarser approach with just morning/afternoon/night, or you can divide it as finely as I did here. Then you'll have the $dayPart variable that matches the name of the part they're in. You can use that to switch the greeting. (I would not hard-code the greeting in the dayParts . Use generic names there, then you can do #if( $dayPart == "Night" ) It's spooky out tonight, isn't it? #end etc.
... View more