Lasso Soft Inc. > Home


AuthorBrad Lindsay
LicensePublic Domain
Posted30 Jun 2009
Updated30 Jun 2009
More by this author...


This tag takes in a string and parses out time components for a duration. It then returns the duration it found. White space, time component order, and extraneous text are ignored. Only the first found instance of a time component is used.

Sample Usage

lsd_string_toduration('1d 17h 45m 22s');
lsd_string_toduration('Duration is 17h 1 d45 m22s');
lsd_string_toduration('Duration is 1 Day 17 Hours 45 Minutes and 22 Seconds');
lsd_string_toduration('17h 1 d45 m22s 0d0h0m0s');

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.

        local('h_abbr') = array('h', 'hour', 'hours', 'hr', 'hrs')->join('|');
        local('m_abbr') = array('m', 'minute', 'minutes', 'min', 'mins')->join('|');
        local('s_abbr') = array('s', 'second', 'seconds', 'sec', 'secs')->join('|');
        //Testing days
        #my_test = regexp(-find='(?i)(\\d+)\\s*(' + #d_abbr + ')(\\b|\\d|\\s)', -input=#a_string);
        local('d') = (#my_test->find ? integer(#my_test->matchstring(1)) | 0);
        //Testing hours
        #my_test = regexp(-find='(?i)(\\d+)\\s*(' + #h_abbr + ')(\\b|\\d|\\s)', -input=#a_string);
        local('h') = (#my_test->find ? integer(#my_test->matchstring(1)) | 0);
        //Testing minutes
        #my_test = regexp(-find='(?i)(\\d+)\\s*(' + #m_abbr + ')(\\b|\\d|\\s)', -input=#a_string);
        local('m') = (#my_test->find ? integer(#my_test->matchstring(1)) | 0);
        //Testing seconds
        #my_test = regexp(-find='(?i)(\\d+)\\s*(' + #s_abbr + ')(\\b|\\d|\\s)', -input=#a_string);
        local('s') = (#my_test->find ? integer(#my_test->matchstring(1)) | 0);

        return(duration(-day=#d, -hour=#h, -minute=#m, -second=#s));


No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft