Page 1 of 1

Simple time syntaxis right

Posted: Fri Apr 30, 2021 7:19 pm
by minimy
Just it, a simple procedure return true or false is syntaxis is good or bad.
8 digit verification format like this 12:30:27 %hh:%ii:%ss
12:30:27 true
a9:10:22 false
1:44:53 false..

Code: Select all

  Procedure isInt(n.s)
    Protected.i p,l,ok
    For l= 1 To Len(n)
      For p='0' To '9'
        If Chr(p)=Mid(n,l,1)
          ok+1
        EndIf
      Next p
    Next l
    If ok=Len(n)
      ProcedureReturn #True
    Else
      ProcedureReturn #False
    EndIf
  EndProcedure

  Procedure isTime(time.s)
    If isInt(Mid(time,1,2)) And isInt(Mid(time,4,2)) And isInt(Mid(time,7,2)) And Mid(time,3,1)=":" And Mid(time,6,1)=":" And Len(time)=8
      ProcedureReturn #True
    Else
      ProcedureReturn #False
    EndIf
  EndProcedure
  
  
CompilerIf #PB_Compiler_IsMainFile

  Debug isTime("22:10:00")
  Debug isTime("02:03:aa")
  
CompilerEndIf

Re: Simple time syntaxis right

Posted: Sat May 01, 2021 2:32 am
by BarryG
Let ParseDate() do the work:

Code: Select all

Procedure IsTime(time$)
  If Len(time$)=8 And ParseDate("%hh:%ii:%ss",time$)>-1
    ok=1
  EndIf
  ProcedureReturn ok
EndProcedure

Debug IsTime("00:00:00") ; 1
Debug IsTime("12:30:27") ; 1
Debug IsTime("22:10:00") ; 1
Debug IsTime("a1:b2:c3") ; 0
Debug IsTime("01-02-03") ; 0
Debug IsTime("1:44:53")  ; 0

Re: Simple time syntaxis right

Posted: Sat May 01, 2021 8:40 pm
by Saki
No offense intended, but such nonsense has no place in T&T.

Re: Simple time syntaxis right

Posted: Sun May 02, 2021 3:52 am
by idle
Saki wrote: Sat May 01, 2021 8:40 pm No offense intended, but such nonsense has no place in T&T.
Dial it down a bit Saki, why is it nonsense? It's a valid Tip the code does what it says. If you don't have something positive or constructive to say It's generally better not to say anything at all.

Re: Simple time syntaxis right

Posted: Sun May 02, 2021 8:25 am
by Saki
Yes, you are right, of course.
I was probably a bit hasty, since I am accustomed to the visual control of the actual time. :oops:

Re: Simple time syntaxis right

Posted: Tue May 04, 2021 7:08 pm
by minimy
Thanks Idle, I appreciate the help.
Yes BarryG with PB you can, thanks for share. But i think is good to know how does at low level. May be im old to post things.. :lol:

Hi saki, greetings and welllcome to the noobs forever world.
I put this like old school example. I know 'millenians' comes with google chip included, but is not bad know how can do by yourself the things.
About is not the section. may be. :shock: . Now in the section, thanks to BarryG and his positive comment, we have other code to use.
Any way.. No problem, no offense me. Thanks for your comments and next time you can include any code to share. Be happy! Be safe!

PB forum is the best! ..or not? may be? is this the right place to say this? sure!!! :lol:

Re: Simple time syntaxis right

Posted: Tue May 04, 2021 7:27 pm
by Saki
Hi, no, I didn't mean to offend you either.
Technically everything is OK.
A tip :
You don't need math for the clock, you can do that in VectorLib quite easily with rotated circle cutouts.

Re: Simple time syntaxis right

Posted: Wed May 05, 2021 12:36 pm
by minimy
Hey Saki! no problem! Be happy friend!
thanks for the trick!