FastTimeInput ( )

Function stats

Average user rating
37
294
9999
Support
FileMaker 8.0 +
Date posted
26 January 2011
Last updated
07 February 2011
Version
Recursive function
No

Author Info
 Fabrice

70 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

FastTimeInput  ( _input )


Parameters

_input  some text vaguely looking like a time


Description

Tags:  time   Interface   Format  

Allows the user to input time data in a more convenient manner, without annoying data type validation errors.
With FileMaker 11, can be used in a triggered script onObjectValidate, to adjust the input time.
Prior to FileMaker 11, you need two fields (a text field for input, and a calculated time field using this function.

The function gives priority to hours over seconds. If the input is both a valid h:m and a valid m:s time, the former will be returned.

Some examples :
(in the input, columns (:) can be replaced by blanks (" ") or dashes (-)

"" (empty) -> "" (empty)
5:30:10    ->    05:30:10
5:9        ->    05:09:00
5        ->    05:00:00
14        ->    14:00:00
45        ->    00:45:00
45:6    ->    00:45:06
23:15    ->    23:15:00
24:15    ->    00:24:15
//        ->    [Current Host Time]
6:12 PM    ->    18:12:00
12:10 PM ->    12:10:00
12:10 AM ->    00:10:00
1210    ->    12:10:00
121025    ->    12:10:25

See also FastDateInput here : http://www.fmfunctions.com/fname/FastDateInput

Examples

Sample input

"" (empty) -> "" (empty)
5:30:10    ->    05:30:10
5:9        ->    05:09:00
5        ->    05:00:00
14        ->    14:00:00
45        ->    00:45:00
45:6    ->    00:45:06
23:15    ->    23:15:00
24:15    ->    00:24:15
//        ->    [Current Host Time]
6:12 PM    ->    18:12:00
12:10 PM ->    12:10:00
12:10 AM ->    00:10:00
1210    ->    12:10:00
121025    ->    12:10:25


Sample output

-

 

Function code

/*
FastTimeInput ( _input )

by Fabrice Nordmann, 1-more-thing
http://www.1-more-thing.com


v1.2        Feb 2011
            - now takes parameters without separator : 1210 -> 12:10:00
            - fixed an issue when passed parameter was of type number
            - includes a test case code to paste into the DataViewer
v1.1        Jan 2011
            - now accepts AM/PM times
v1.        Jan 2011


Allows the user to input time data in a more convenient manner, without annoying data type validation errors.
With FileMaker 11, can be used in a triggered script onObjectValidate, to adjust the input time.
Prior to FileMaker 11, you need two fields (a text field for input, and a calculated time field using this function.

The function gives priority to hours over seconds. If the input is both a valid h:m and a valid m:s time, the former will be returned.

Some examples :
(in the input, columns (:) can be replaced by blanks (" ") or dashes (-)

"" (empty) -> "" (empty)
5:30:10    ->    05:30:10
5:9        ->    05:09:00
5        ->    05:00:00
14        ->    14:00:00
45        ->    00:45:00
45:6    ->    00:45:06
23:15    ->    23:15:00
24:15    ->    00:24:15
//        ->    [Current Host Time]
6:12 PM    ->    18:12:00
12:10 PM ->    12:10:00
12:10 AM ->    00:10:00
1210    ->    12:10:00
121025    ->    12:10:25

See also FastDateInput here : http://www.fmfunctions.com/fname/FastDateInput

*/

/*
//=====================================
// FastTimeInput TEST CASES (to paste into the DataViewer)
Let ([
    _testCases = Substitute ( List (
        FastTimeInput ( "5:30:10" ) = Time ( 5 ; 30 ; 10 ) ; // TEST #1
        FastTimeInput ( "5:9" ) = Time ( 5 ; 9 ; 0 ) ;
        FastTimeInput ( "5" ) = Time ( 5 ; 0 ; 0 ) ;
        FastTimeInput ( 5 ) = Time ( 5 ; 0 ; 0 ) ;
        FastTimeInput ( "14" ) = Time ( 14 ; 0 ; 0 ) ; // TEST #5
        FastTimeInput ( 14 ) = Time ( 14 ; 0 ; 0 ) ;
        FastTimeInput ( "45" ) = Time ( 0 ; 45 ; 0 ) ;
        FastTimeInput ( 45 ) = Time ( 0 ; 45 ; 0 ) ;
        FastTimeInput ( "45:6" ) = Time ( 0 ; 45 ; 6 ) ;
        FastTimeInput ( "23:15" ) = Time ( 23 ; 15 ; 0 ) ; // TEST #10
        FastTimeInput ( "24:15" ) = Time ( 0 ; 24 ; 15 ) ;
        FastTimeInput ( "6:12 PM" ) = Time ( 18 ; 12 ; 0 ) ;
        FastTimeInput ( "12:10 PM" ) = Time ( 12 ; 10 ; 0 ) ;
        FastTimeInput ( "12:10 AM" ) = Time ( 0 ; 10 ; 0 ) ;
        FastTimeInput ( "1210" ) = Time ( 12 ; 10 ; 0 ) ; // TEST #15
        FastTimeInput ( 1210 ) = Time ( 12 ; 10 ; 0 ) ;
        FastTimeInput ( "2410" ) = Time ( 0 ; 24 ; 10 ) ;
        FastTimeInput ( 2410 ) = Time ( 0 ; 24 ; 10 ) ;
        FastTimeInput ( "65:24:10" ) = Time ( 65 ; 24 ; 10 ) ;
        FastTimeInput ( "65:62:10" ) = Time ( 66 ; 2 ; 10 ) ; // TEST #20
        FastTimeInput ( "65:62:62" ) = Time ( 66 ; 3 ; 2 )
        ) ; ¶ ; "" ) ;
    _posError = Position ( _testCases ; 0 ; 1 ; 1 ) ;
    _validation = "FastTimeInput: " & Case ( _posError ; "• /!\ ERROR ON TEST " & _posError & " /!\ •" ; "OK" )
    
    ];
    _validation
)
//=====================================
*/



Let ( _input = GetAsText ( Trim ( _input )) ;

Case (
    _input = GetAsTime ( _input ) ; GetAsTime ( _input ) ; // input is a valid time, leave it untouched
    _input = "//" ; GetAsTime ( Get ( CurrentHostTimeStamp )) ; // current host time
    _input = Filter ( _input ; 1234567890 ) ; Case ( GetAsNumber ( Middle ( _input ; 1 ; 2 )) > 23 ; Time ( 0 ; Middle ( _input ; 1 ; 2 ) ; Middle ( _input ; 3 ; 2 )) ; Time ( 0 + Middle ( _input ; 1 ; 2 ) ; 0 + Middle ( _input ; 3 ; 2 ) ; 0 + Middle ( _input ; 5 ; 2 ))) ;

Let ([
    _i = Substitute ( Filter ( _input ; "1234567890 :-" ) ; [":" ; " "] ; [ "-" ; " " ] ) ;
    _merid = Case (
            PatternCount ( _input ; "AM" ) ; "AM" ;
            PatternCount ( _input ; "PM" ) ; "PM"
        ) ;
    _clock = Case ( not IsEmpty ( _merid ) ; 12 ; 23 ) ; // 12 AM exists, but 23 is the last displayed hour.
    _str = Case (
        WordCount ( _i ) = 3 ; "HMS" ;
        WordCount ( _i ) = 2 ; Case ( GetAsNumber ( MiddleWords ( _i ; 1 ; 1 )) <= _clock ; "HM" ; "MS" ) ;
        WordCount ( _i ) = 1 ; Case ( GetAsNumber ( MiddleWords ( _i ; 1 ; 1 )) <= _clock ; "H" ; "M" )
        ) ;
    _h = 0 + Case ( PatternCount ( _str ; "H" ) ; GetAsNumber ( MiddleWords ( _i ; Position ( _str ; "H" ; 1 ; 1 ) ; 1 ))) ;
    _h = Case ( _merid = "AM" and _h = 12 ; 0 ; _merid = "PM" and _h <> 12 ; _h + 12 ; _h ) ;
    _m = 0 + Case ( PatternCount ( _str ; "M" ) ; GetAsNumber ( MiddleWords ( _i ; Position ( _str ; "M" ; 1 ; 1 ) ; 1 ))) ;
    _s = 0 + Case ( PatternCount ( _str ; "S" ) ; GetAsNumber ( MiddleWords ( _i ; Position ( _str ; "S" ; 1 ; 1 ) ; 1 )))
];

Time ( _h ; _m ; _s )
)
)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/294

    Prototype: FastTimeInput( _input )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 07 February 2011
    Version: 1.5

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (31)
Date  (26)
List  (26)
Format  (23)
XML  (22)
Sql  (18)
Dev  (18)
Debug  (15)
Interface  (13)
Text  (13)
Layout  (13)
Variables  (12)
Filter  (11)
Design  (10)
Layout Objects  (8)
Timestamp  (7)