Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. USING: io.encodings.utf8 combinators combinators.smart calendar
  2. io kernel math sequences splitting formatting.private ascii calendar.unix io.files
  3. calendar.format ;
  4.  
  5. IN: prova
  6.  
  7. ! : read-historic (fname -- a ) current-timeval timeval>seconds ;
  8. ! : file-lines (fname -- arr ) utf8 <file-reader> [ readln ] with-input-stream ;
  9.  
  10. ! "/tmp/times.txt" utf8 file-lines
  11.  
  12. ! current-timeval timeval>unix-time >date
  13.  
  14. ! unix-time>timestamp
  15.  
  16. ! "2017-03-29 00:00:00" ymdhms>timestamp
  17.  
  18. ! regexes are crap
  19.  
  20. : in/out-for-timestamp ( ts -- d ) " " split first ;
  21.  
  22. : date-for-timestamp ( ts -- d ) " " split second ;
  23.  
  24. ! : hour-for-timestamp ( ts -- d ) " " split third ;
  25.  
  26. ! : for-clocking-in ( fn -- l ) utf8 file-lines ;
  27.  
  28. ! "/tmp/times.txt" utf8 file-lines [ " " split ] map [ first "in" = ] ;
  29.  
  30. : base-for-date ( h l -- h ) date-for-timestamp swap at unix-1970 or ;
  31.  
  32. : seconds-for ( l -- ts ) " " split 1 tail " " join ymdhms>timestamp ;
  33.  
  34. : process-line ( h l -- h x ) dup [ base-for-date ] [ seconds-for ] [ in/out-for-timestamp "in" = [ time- ] [ time+ ] if ] tri ;
  35.  
  36. H{ } clone "in 2017-03-19 00:00:00" [ base-for-date ] [ seconds-for ] [ in/out-for-timestamp "in" = [ time- ] [ time+ ] if ] tri
  37.  
  38. H{ } clone "in 2017-03-19 00:00:00" process-line
  39.  
  40.  
  41. "in 2017-03-19 00:00:00" seconds-for
  42.  
  43.  
  44. : foo ( x -- x ) " " split first ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement