Does Such A Tag Already Exist?

View: New views
10 Messages — Rating Filter:   Alert me  

Does Such A Tag Already Exist?

by Brad Lindsay-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Before I go off and write this tag myself, I was wondering if a tag  
existed to parse / cast into a duration a string of the following  
format: '1d 17h 45m 22s'

I haven't found any searching through tagSwap, but I thought I might  
be missing something.

-Brad

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't think it exists yet.  If you create one, please do post it to tagswap.net.

I would start off by taking the string, '1d 17h 45m 22s', split on space, then parse each element in the resulting array.

Ultimately you would end up with this:

    var('mydur' = duration($h + ':' + $m + ':' + $s));
    $mydur;

=> 41:45:22

--steve


On Tuesday, June 30, 2009, blindsay@... (Brad Lindsay) pronounced:

>Before I go off and write this tag myself, I was wondering if a tag  
>existed to parse / cast into a duration a string of the following  
>format: '1d 17h 45m 22s'
>
>I haven't found any searching through tagSwap, but I thought I might  
>be missing something.
>
>-Brad
>
>--
>This list is a free service of LassoSoft: http://www.LassoSoft.com/
>Search the list archives: http://www.ListSearch.com/Lasso/Browse/
>Manage your subscription: http://www.ListSearch.com/Lasso/
>
>

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by Brad Lindsay-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jun 30, 2009, at 1:44 PM, Steve Piercy - Web Site Builder wrote:
> I don't think it exists yet.  If you create one, please do post it  
> to tagswap.net.

I definitely will.


> I would start off by taking the string, '1d 17h 45m 22s', split on  
> space, then parse each element in the resulting array.

I was thinking of starting by removing the spaces - making them  
optional.  However, do you think I should enforce the logical order?  
In other words, should you have to put minutes before seconds, or  
should you be able to reference them in any order? (I'm leaning  
towards allowing them to be specified in any order)

-Brad

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by Brian Loomis-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I would split on spaces and then see if the array elements contain h,  
m, d, or s

then put them into your own order.

also assert that the format only has one instance of each  h, m, d, or  
s in each part.

On Jun 30, 2009, at 11:52 AM, Brad Lindsay wrote:

>
> On Jun 30, 2009, at 1:44 PM, Steve Piercy - Web Site Builder wrote:
>> I don't think it exists yet.  If you create one, please do post it  
>> to tagswap.net.
>
> I definitely will.
>
>
>> I would start off by taking the string, '1d 17h 45m 22s', split on  
>> space, then parse each element in the resulting array.
>
> I was thinking of starting by removing the spaces - making them  
> optional.  However, do you think I should enforce the logical  
> order?  In other words, should you have to put minutes before  
> seconds, or should you be able to reference them in any order? (I'm  
> leaning towards allowing them to be specified in any order)
>
> -Brad
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>

Brian Loomis
http://www.virtualrelations.us
(208) 639-2569 - 208 NEW BLOX
-- email checked daily --


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by Jason Huck :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This would work with any order, but would need to be space-delimited:

define_tag('string_toduration', -req='in');
    local('d' = 0, 'h' = 0, 'm' = 0, 's' = 0);
    iterate(#in->split(' '), local('i'));
        local('u') = string(#i)->removeleading(integer(#i))&;
        local(#u) = integer(#i);
    /iterate;
    return(duration( -day=#d, -hour=#h, -minute=#m, -second=#s));
/define_tag;

string_toduration('1d 17h 45m 22s');


- jason



On Tue, Jun 30, 2009 at 1:52 PM, Brad Lindsay<blindsay@...> wrote:

>
> On Jun 30, 2009, at 1:44 PM, Steve Piercy - Web Site Builder wrote:
>>
>> I don't think it exists yet.  If you create one, please do post it to
>> tagswap.net.
>
> I definitely will.
>
>
>> I would start off by taking the string, '1d 17h 45m 22s', split on space,
>> then parse each element in the resulting array.
>
> I was thinking of starting by removing the spaces - making them optional.
>  However, do you think I should enforce the logical order?  In other words,
> should you have to put minutes before seconds, or should you be able to
> reference them in any order? (I'm leaning towards allowing them to be
> specified in any order)
>
> -Brad
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>
>



--
tagSwap.net :: Open Source Lasso Code
<http://tagSwap.net/>

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by bilcorry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jason Huck wrote on 6/30/2009 12:58 PM:
> This would work with any order, but would need to be space-delimited:

Building on yours, this makes the whitespace unimportant, the order is unimportant, extraneous text is unimportant, and only uses the first found instance of each time component:

=========================================================
[

define_tag('string_toduration', -req='in');
        local('d' = 0, 'h' = 0, 'm' = 0, 's' = 0);
        protect; #d = integer(string_findregexp(#in,-find='(?i)(\\d+)\\s*d')->get(2)); /protect;
        protect; #h = integer(string_findregexp(#in,-find='(?i)(\\d+)\\s*h')->get(2)); /protect;
        protect; #m = integer(string_findregexp(#in,-find='(?i)(\\d+)\\s*m')->get(2)); /protect;
        protect; #s = integer(string_findregexp(#in,-find='(?i)(\\d+)\\s*s')->get(2)); /protect;
        return(duration( -day=#d, -hour=#h, -minute=#m, -second=#s));
/define_tag;

string_toduration('1d 17h 45m 22s');'<br>';
string_toduration('Duration is 17h 1 d45 m22s');'<br>';
string_toduration('Duration is 1 Day 17 Hours 45 Minutes and 22 Seconds');'<br>';
string_toduration('17h 1 d45 m22s 0d0h0m0s');'<br>';
]

LP8:  41:45:22
      41:45:22
      41:45:22
      41:45:22
=========================================================


- Bil


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by Brad Lindsay-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bil,
This is awesome!  One quick question about your regular expression.  
What does (?i) do?  Why are you starting everything with it?

Also, I do want to modify this a bit further.  Once I'm done, is it  
alright if I post it at tagSwap, or do you want to create a Lasso Pro  
tag for it?

Thanks,
-Brad

On Jun 30, 2009, at 2:36 PM, Bil Corry wrote:

> Jason Huck wrote on 6/30/2009 12:58 PM:
>> This would work with any order, but would need to be space-delimited:
>
> Building on yours, this makes the whitespace unimportant, the order  
> is unimportant, extraneous text is unimportant, and only uses the  
> first found instance of each time component:
>
> =========================================================
> [
>
> define_tag('string_toduration', -req='in');
> local('d' = 0, 'h' = 0, 'm' = 0, 's' = 0);
> protect; #d = integer(string_findregexp(#in,-find='(?i)(\\d+)\
> \s*d')->get(2)); /protect;
> protect; #h = integer(string_findregexp(#in,-find='(?i)(\\d+)\
> \s*h')->get(2)); /protect;
> protect; #m = integer(string_findregexp(#in,-find='(?i)(\\d+)\
> \s*m')->get(2)); /protect;
> protect; #s = integer(string_findregexp(#in,-find='(?i)(\\d+)\
> \s*s')->get(2)); /protect;
> return(duration( -day=#d, -hour=#h, -minute=#m, -second=#s));
> /define_tag;
>
> string_toduration('1d 17h 45m 22s');'<br>';
> string_toduration('Duration is 17h 1 d45 m22s');'<br>';
> string_toduration('Duration is 1 Day 17 Hours 45 Minutes and 22  
> Seconds');'<br>';
> string_toduration('17h 1 d45 m22s 0d0h0m0s');'<br>';
> ]
>
> LP8:  41:45:22
>      41:45:22
>      41:45:22
>      41:45:22
> =========================================================
>
>
> - Bil
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>
>


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by Brad Lindsay-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jun 30, 2009, at 2:52 PM, Brad Lindsay wrote:
> Bil,
> This is awesome!  One quick question about your regular expression.  
> What does (?i) do?  Why are you starting everything with it?

Oh! Does it make the matching case-insensitive?

-Brad


>
> Also, I do want to modify this a bit further.  Once I'm done, is it  
> alright if I post it at tagSwap, or do you want to create a Lasso  
> Pro tag for it?
>
> Thanks,
> -Brad
>
> On Jun 30, 2009, at 2:36 PM, Bil Corry wrote:
>> Jason Huck wrote on 6/30/2009 12:58 PM:
>>> This would work with any order, but would need to be space-
>>> delimited:
>>
>> Building on yours, this makes the whitespace unimportant, the order  
>> is unimportant, extraneous text is unimportant, and only uses the  
>> first found instance of each time component:
>>
>> =========================================================
>> [
>>
>> define_tag('string_toduration', -req='in');
>> local('d' = 0, 'h' = 0, 'm' = 0, 's' = 0);
>> protect; #d = integer(string_findregexp(#in,-find='(?i)(\\d+)\
>> \s*d')->get(2)); /protect;
>> protect; #h = integer(string_findregexp(#in,-find='(?i)(\\d+)\
>> \s*h')->get(2)); /protect;
>> protect; #m = integer(string_findregexp(#in,-find='(?i)(\\d+)\
>> \s*m')->get(2)); /protect;
>> protect; #s = integer(string_findregexp(#in,-find='(?i)(\\d+)\
>> \s*s')->get(2)); /protect;
>> return(duration( -day=#d, -hour=#h, -minute=#m, -second=#s));
>> /define_tag;
>>
>> string_toduration('1d 17h 45m 22s');'<br>';
>> string_toduration('Duration is 17h 1 d45 m22s');'<br>';
>> string_toduration('Duration is 1 Day 17 Hours 45 Minutes and 22  
>> Seconds');'<br>';
>> string_toduration('17h 1 d45 m22s 0d0h0m0s');'<br>';
>> ]
>>
>> LP8:  41:45:22
>>     41:45:22
>>     41:45:22
>>     41:45:22
>> =========================================================
>>
>>
>> - Bil
>>
>>
>> --
>> This list is a free service of LassoSoft: http://www.LassoSoft.com/
>> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
>> Manage your subscription: http://www.ListSearch.com/Lasso/
>>
>>
>>
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>
>
>


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by bilcorry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Brad Lindsay wrote on 6/30/2009 1:52 PM:
> Bil,
> This is awesome!  One quick question about your regular expression.
> What does (?i) do?  Why are you starting everything with it?

It's the case-insensitive switch.


> Also, I do want to modify this a bit further.  Once I'm done, is it
> alright if I post it at tagSwap, or do you want to create a Lasso Pro
> tag for it?

Please post it to tagSwap.  I may eventually add it to the LP library, but it won't be any time soon.


- Bil


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: Does Such A Tag Already Exist?

by Brad Lindsay-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jun 30, 2009, at 1:28 PM, Brad Lindsay wrote:
> Before I go off and write this tag myself, I was wondering if a tag  
> existed to parse / cast into a duration a string of the following  
> format: '1d 17h 45m 22s'
> I haven't found any searching through tagSwap, but I thought I might  
> be missing something.

I finished the tag, and made some modifications and have posted it to  
tagSwap: http://tagswap.net/LSD_String_ToDuration/

Below is the final code that allows for multiple different types of  
abbreviations for each time component.  Please feel free to review and  
point out any uncaught bugs or errors.

Thanks,
-Brad


<?LassoScript
     define_tag('LSD_String_ToDuration', -required='a_string');
         // This tag takes in inputs and tries to match numbers that  
are next to certain abbreviations.
         // Based on that data, it returns a duration type.
         //
         // Whitespace is unimportant, the order is unimportant,  
extraneous text is unimportant,
         //and only the first found instance of each time component is  
used
         local('my_test');
         //We're limiting this to certain abbreviations
         //Feel free to add your abbreviations here
         local('d_abbr') = array('d', 'day', 'days')->join('|');
         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));
     /define_tag;
?>



--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/