[jawsscripts] Re: howTo translate numeric timer into speaking mins and secs?

  • From: "Gordon Luke" <Gordon.Luke@xxxxxxxxxxxxxxxx>
  • To: jawsscripts@xxxxxxxxxxxxx
  • Date: Fri, 23 Jul 2010 10:50:20 +0100

Hi Geoff

I hope the below will do the trick for you.  I think it should handle all
your time needs and I hope the comments within the code help to explain
things OK.  If not give me a shout.

include "HjConst.jsh"


String function GetTimeName(String sTime,int iSegment,String sTimeName,bool
bShowZero)
Var
        int iAmount

        ; Turn the string into an integer for easier processing
        let iAmount = StringtoInt(StringSegment (sTime, ":", iSegment))

        ; Is there any time here and do we need to show it?
        if (iAmount == 0) && (bShowZero == false) then
                return ""
        endif

        ; If we've only got 1 then we don't want to pluralise the amount
        if (iAmount == 1) then
                return "1 " + sTimeName
        endif

        ; Return the value with the time interval pluralised
        return IntToString(iAmount) + " " + sTimeName + "s"
endfunction

String function StringTime(string sTime)
Var
        string sresult,
        string sEnd

        ; Make sure we have 3 segments
        while (StringSegmentCount (sTime, ":") < 3)
                let sTime = "00:" + sTime
        endwhile

        ; Get the time in hours and minutes
        let sResult = StringTrimTrailingBlanks 
(GetTimeName(sTime,1,"hour",false)
+ " " + GetTimeName(sTime,2,"minute",false))

        ; Get the seconds time
        let sEnd = GetTimeName(sTime,3,"second",true)

        ; If we've got only seconds then that's all we send back
        if (sResult == "") then
                return sEnd
        endif

        ; Join the two times together with the word and
        return sResult + " and " + sEnd
endfunction

Script Test ()
   SayString(StringTime("01:42"))

EndScript

Gordon Luke
Capita IT (CAIM)


                                                                       
             "Geoff Chapman"                                           
             <gch@xxxxxxxxxxxx                                         
             t.au>                                                      To
             Sent by:                  <jawsscripts@xxxxxxxxxxxxx>     
             jawsscripts-bounc                                          cc
             e@xxxxxxxxxxxxx                                           
                                                                   Subject
                                       [jawsscripts] howTo translate   
                                       numeric timer into speaking mins
                                       and secs?                       
             23/07/2010 05:02                                          
                                                                       
             Please respond to                                         
             jawsscripts@freel                                         
                 ists.org                                              
                                                                       
                                                                       




Mighty scripters. would any kind soul feel so able/inclined today, to
assist me ever so greatly, by either perhaps providing some actual code, or
pointers,
 with which I might be able to process a colon delimited numeric string,
into more friendly speaking of seconds, or minutes and seconds
respectively?
as in,
x seconds. or x minutes x seconds?

the timer string always has a minimum of 4 digits delimited by a colon, as
in
2 digits, then colon, then another 2 digits, even when seconds only, like
this:

00:40

means it's been onHold for 40 seconds etc.

It does do hours as well, as I have here on my test system, <grin,> but I
severely doubt I have to cover that, as noone's gunna hang around onn Hold
in a business for xx hours, x minutes and x seconds eh.
<smile.>

However, I'd love it also for the output to be intelligent enough not to
announce 0 minutes x seconds, when there was only 0 in the minutes column?

Would anyone feel like they could assist with this one today? or, if not
time, point me in dirrection of how I might begin to tackle the problem?


no builtins I guess to already handle this? it must be a common enough
occurrance/desire I'd have thought?

my sincerest thanks for any tips/guidance.

 Geoff c.



__________�

View the list's information and change your settings at
http://www.freelists.org/list/jawsscripts




This email is confidential and should not be used by anyone who is not
the original intended recipient. Prudential cannot accept liability
for statements made which are clearly the sender's own and not made
on behalf of the Prudential. In addition, no statement should be
construed as giving investment advice within or outside the United
Kingdom.

Prudential plc, incorporated and registered in England and Wales.
Registered Office at Laurence Pountney Hill, London, EC4R 0HH.
Registered number 1397169. Prudential plc is a holding company,
subsidiaries of which are authorised and regulated by the Financial
Services Authority (FSA).

'Prudential' is a trading name of The Prudential Assurance Company
Limited, which is incorporated and registered in England and Wales.
Registered Office at Laurence Pountney Hill, London, EC4R 0HH.
Registered number 15454. Authorised and regulated by the Financial
Services Authority. 'Prudential' is also used by other companies within
the Prudential Group, which between them provide a range of financial
products including life assurance, pensions, savings and investment
products.

'Prudential' is also a trading name of Prudential Distribution Limited, 
which is incorporated and registered in Scotland.  Registered Office at 
Craigforth, Stirling, FK9 4UE.  Registered number SC212640. Authorised 
and regulated by the Financial Services Authority.

A list of other Prudential companies together with their registered
statutory details can be found in 'About Prudential' on 
http://www.prudential.co.uk

An email reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.

__________�

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts

Other related posts: