[time_ampmto24]

Description

Link: [time_ampmto24]
Author: Steve Piercy
Category: Date
Version: 8.5.x
License: Public Domain
Posted: Dec. 20, 2010
Updated: Dec. 21, 2010
More by this author...

Humans and computers often have problems understanding one another, especially concerning times.

Entering times is tedious, especially when it is broken apart into 3 select menus (hours, minutes, am/pm).  That is too many clicks!

Some programmers "punt" the issue by combining the hours and AM/PM indicator into a single field with 24-hour time.  Computers understand this format, but humans often incorrectly enter 17:00 when they mean to enter 7:00 PM.

To mitigate the user interface issue, I use this jQuery plugin for entering times.

http://keith-wood.name/timeEntry.html

However this means that times must be converted to a format that computers understand.  This custom tag handles the issue.

Parameters

-t string, required Time in the format of "hh:mm AP"

Sample Usage

var('t1') = '07:00 AM';
var('t2') = '07:00 PM';
var('t3') = '07:00PM';

<h3>[time_ampmto24($t1)]</h3>
<h3>[time_ampmto24($t2)]</h3>
<h3>[time_ampmto24($t3)]</h3>

=>
07:00:00
19:00:00
Value is not in the proper time format of "hh:mm AP".
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
define_tag('time_ampmto24', -required='t', -description='Converts times formatted as hh:mm AM/PM to 24-hour format.');
/*
Humans and computers often have problems understanding one another, especially concerning times.

Entering times is tedious, especially when it is broken apart into 3 select menus (hours, minutes, am/pm).  That is too many clicks!

Some programmers "punt" the issue by combining the hours and AM/PM indicator into a single field with 24-hour time.  Computers understand this format, but humans often incorrectly enter 17:00 when they mean to enter 7:00 PM.

To mitigate the user interface issue, I use this jQuery plugin for entering times.

http://keith-wood.name/timeEntry.html

However this means that times must be converted to a format that computers understand.  This custom tag handles the issue.

Sample Usage
------------------------------
var('t1') = '07:00 AM';
var('t2') = '07:00 PM';
var('t3') = '07:00PM';

<h3>[time_ampmto24($t1)]</h3>
<h3>[time_ampmto24($t2)]</h3>
<h3>[time_ampmto24($t3)]</h3>

07:00:00
19:00:00
Value is not in the proper time format of "hh:mm AP".

*/
	if(string_findregexp(#t, -find='^\\d{2}:\\d{2} [A|P]M$')->size!=1);
		return('Value is not in the proper time format of "hh:mm AP".');
	/if;
	#t=#t->split(' ');
	if(#t->get(2) == 'PM' && !#t->get(1)->beginswith('12'));
		#t=#t->get(1);
		#t=date_add(date('2010-01-01 '+#t), -hour=12);
	else;
		#t=#t->get(1);
		#t=date('2010-01-01 '+#t);
	/if;
	#t=#t->format('%T');
	return(#t);
/define_tag;

 

Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net