Blog
New function - getMeridiem
I just submitted a function to CFLib.org and thought I'd post it here too. getMeridiem() isn't super fancy, it just returns the "AM/PM" portion of a datetime (the name of which is the "meridiem"). As you can see, you can get that information from the built-in function TimeFormat(). All I'm doing is adding a little extra whitespace housecleaning and validation (which is useful if the dates might be badly formed...a situation I ran into last week...hence my writing this function). Also, I find getMeridiem() is a more intuitive name and it's more clear what that function does than TimeFormat( theTime, "tt" )...self documenting code and all that.
The source code and examples look like so:
2 <cfargument name="timePassedIn" type="string" required="true" />
3
4 <cfset var meridiem = "" />
5
6 <cfset arguments.timePassedIn = Trim( arguments.timePassedIn ) />
7 <cfif not IsDate( arguments.timePassedIn )>
8 <cfreturn meridiem />
9 <cfelse>
10 <cfset meridiem = TimeFormat( arguments.timePassedIn, "tt" ) />
11 </cfif>
12
13 <cfreturn meridiem />
14
15</cffunction>
Examples:
<cfoutput>
#getMeridiem( "4/2/2012 14:33:00" )#
#getMeridiem( "14:33:00" )#
#getMeridiem( CreateTime( 17, 30, 00 ) )#
</cfoutput>
Feel free to add this to your own Date/Time libraries for later use. Feedback is welcome.
-nolan


Thanks for submitting this UDF. Unfortunately I've just rejected it :-(
Here's why. You've specified the argument as a DATE, so all the trim() and isDate() stuff is redundant (the value won't get that far if it's not already a date), leaving just the timeFormat() bit. And it's more work for people to grab your UDF, include it in their code and call it than just to use timeFormat(). This is especially so because it's always gonna be better to use a built-in function than a UDF that - for all intents and purposes - does the same as the built-in function.
I hope you don't find this discouraging: CFLib certainly does appreciate that you thought to submit this, and hope you continue to submit your UDFs.
Cheers / sorry.
--
Adam