Re: Parsing timestamps?

Liste des GroupesRevenir à cl forth 
Sujet : Re: Parsing timestamps?
De : melahi_ahmed (at) *nospam* yahoo.fr (Ahmed)
Groupes : comp.lang.forth
Date : 08. Oct 2024, 19:12:14
Autres entêtes
Organisation : novaBBS
Message-ID : <e8d0009d34971a6c9a2e1df583843a10@www.novabbs.com>
References : 1 2 3
User-Agent : Rocksolid Light
Hi, Here is a programme that uses your split word.
I think it works for all combinations (formats).
\ here begins the code
: SPLIT ( a u c -- a2 u2 a3 u3 )  >r 2dup r> scan 2swap 2 pick - ;
: advance 1- swap 1+ swap ;
: .00?1
   dup 1 3 within 0= if 2drop  s" 00"   then
;
: .00?2
   dup 0=            if 2drop s" 00" exit then
   dup 1 3 within 0= if 2drop  2swap 2>r s" 00" 2swap 2r>   then
;
: .00?3
   dup 0=            if  2drop s" 00" exit then
   dup 1 3 within 0= if  2drop 2swap    2>r s" 00" 2rot 2rot 2r> then
;
: step1 [char] : split 2swap 2>r .00?1 2swap 2r> advance ;
: step2 [char] : split 2swap 2>r .00?2 2swap 2r> advance ;
: step3 [char] : split 2swap 2>r .00?3 2swap 2r> advance ;
: :t  s" --" 2swap step1 step2 step3  2drop 2drop ;
: sts space type space ;
: .hr  sts ." hr"  ;
: .min sts ." min" ;
: .sec sts ." sec" ;
: .t 2>r 2swap .hr .min 2r> .sec ;
\ the code finshes here.
Some tests (gforth under wsl):
s" 10:20:30" :t .t  10 hr 20 min 30 sec ok
s" 1:20:30" :t .t  1 hr 20 min 30 sec ok
s" 1:2:30" :t .t  1 hr 2 min 30 sec ok
s" 1:2:3" :t .t  1 hr 2 min 3 sec ok
s" :2:3" :t .t  00 hr 2 min 3 sec ok
s" 2:3" :t .t  00 hr 2 min 3 sec ok
s" :3" :t .t  00 hr 00 min 3 sec ok
s" ::3" :t .t  00 hr 00 min 3 sec ok
s" ::" :t .t  00 hr 00 min 00 sec ok
s" :" :t .t  00 hr 00 min 00 sec ok
s" " :t .t  00 hr 00 min 00 sec ok
s" 1:" :t .t  00 hr 1 min 00 sec ok
s" :1:" :t .t  00 hr 1 min 00 sec ok
s" 10::" :t .t  10 hr 00 min 00 sec ok
s" 10:5:" :t .t  10 hr 5 min 00 sec ok
s" 10:5:2" :t .t  10 hr 5 min 2 sec ok
Ahmed
--

Date Sujet#  Auteur
6 Oct 24 * Parsing timestamps?45dxf
6 Oct 24 +* Re: Parsing timestamps?8mhx
6 Oct 24 i+* Re: Parsing timestamps?3dxf
6 Oct 24 ii`* Re: Parsing timestamps?2dxf
7 Oct 24 ii `- Re: Parsing timestamps?1dxf
7 Jun13:38 i`* Re: Parsing timestamps?4B. Pym
7 Jun15:36 i `* Re: Parsing timestamps?3dxf
7 Jun18:07 i  `* Re: Parsing timestamps?2LIT
8 Jun03:38 i   `- Re: Parsing timestamps?1dxf
6 Oct 24 +* Re: Parsing timestamps?5Ruvim
6 Oct 24 i`* Re: Parsing timestamps?4dxf
6 Oct 24 i `* Re: Parsing timestamps?3Ruvim
6 Oct 24 i  +- Re: Parsing timestamps?1Ruvim
6 Oct 24 i  `- Re: Parsing timestamps?1Ruvim
6 Oct 24 +* Re: Parsing timestamps?6FFmike
6 Oct 24 i`* Re: Parsing timestamps?5FFmike
7 Oct 24 i `* Re: Parsing timestamps?4dxf
7 Oct 24 i  `* Re: Parsing timestamps?3FFmike
7 Oct 24 i   `* Re: Parsing timestamps?2dxf
7 Oct 24 i    `- Re: Parsing timestamps?1FFmike
6 Oct 24 +* Re: Parsing timestamps?2Anthony Howe
7 Oct 24 i`- Re: Parsing timestamps?1dxf
7 Oct 24 +* Re: Parsing timestamps?9albert
7 Oct 24 i`* Re: Parsing timestamps?8dxf
7 Oct 24 i `* Re: Parsing timestamps?7sjack
8 Oct 24 i  `* Re: Parsing timestamps?6dxf
8 Oct 24 i   +* Re: Parsing timestamps?3Ahmed
8 Oct 24 i   i+- Re: Parsing timestamps?1dxf
8 Oct 24 i   i`- Re: Parsing timestamps?1sjack
8 Oct 24 i   `* Re: Parsing timestamps?2sjack
9 Oct 24 i    `- Re: Parsing timestamps?1dxf
8 Oct 24 +* Re: Parsing timestamps?3albert
8 Oct 24 i`* Re: Parsing timestamps?2dxf
8 Oct 24 i `- Re: Parsing timestamps?1Ahmed
9 Oct 24 +* Re: Parsing timestamps?4alaa
10 Oct 24 i+* Re: Parsing timestamps?2dxf
10 Oct 24 ii`- Re: Parsing timestamps?1alaa
16 Oct 24 i`- Re: Parsing timestamps?1Hans Bezemer
18 Oct 24 `* Re: Parsing timestamps?7Gerry Jackson
19 Oct 24  `* Re: Parsing timestamps?6dxf
28 Oct 24   `* Re: Parsing timestamps?5Hans Bezemer
29 Oct 24    `* Re: Parsing timestamps?4dxf
29 Oct 24     `* Re: Parsing timestamps?3Hans Bezemer
30 Oct 24      `* Re: Parsing timestamps?2dxf
31 Oct 24       `- Re: Parsing timestamps?1dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal