Paste: my 9-based time (2)

Author: randy7
Mode: factor
Date: Thu, 15 Jan 2009 18:10:06
Plain Text |
USING: calendar kernel math math.functions math.parser
sequences ;

IN: 9time
 
: insert-between ( str joiner -- str' ) 
    [ [ 1string ] { } map-as ] dip join ;


: (nine-time) ( date -- 9time )
    now swap time-
    duration>seconds 
    1/6 * ! 2 nhrs = 12 hrs (seconds are different) all the rest is multiples of 9 
    floor
    9 >base [ string>number ]
            [ length "1" <repetition> concat string>number ] bi
    + 
    number>string ":" insert-between ;

: nine-time ( -- ) 1992 5 13 <date> (nine-time) . ;

Annotation: fixed - different algo

Author: randy7
Mode: factor
Date: Tue, 20 Jan 2009 12:13:16
Plain Text |
USING: calendar kernel math math.functions math.parser
       prettyprint sequences strings ;
IN: 9time

: time-start ( -- date ) 1992 5 13 <date> ; inline
: nyears-until ( date -- seconds )
    time-start time- duration>seconds 43200 / ! ndays
    9 / ! nweeks
    9 / ! nmonths
    9 / ! nyears
    ;

: as-9-base ( item -- 9base-digit ) 1+ floor 9 >base string>number ;

: down-nine ( time -- rem*9 ) dup floor - 9 * ; 

: down-nine2 ( time -- rem*9/i rem*9 ) [ down-nine floor as-9-base ] [ down-nine ] bi ;
: nyears ( nyear-float -- nyear-int nyear-float ) dup floor as-9-base swap ;
: nmonths   ( nyear-float -- nmonth-int nmonth-float ) down-nine2 ;
: nweeks ( nmonth-float -- nweek-int nweek-float ) down-nine2 ;
: ndays ( nweek-float -- ndays-int ndays-float ) down-nine2 ;
: nhours ( ndays-float -- nhours-int nhours-float ) down-nine2 ;
: nminutes ( nhours-float -- nminutes-int nminutes-float ) down-nine2 ;
: nseconds ( nminutes-float -- nseconds-int nseconds-float ) down-nine2 ;
: nnseconds ( nseconds-float -- nnseconds-int ) down-nine as-9-base ;

: nyears>ntimestamp ( nyear-float -- array )
    [ nyears nmonths nweeks ndays nhours nminutes nseconds nnseconds ] 
    [ call ] [ length narray ] bi ;

: (time-str) [ number>string ] map ":" join ; 
: date>9time ( <date> -- str ) nyears-until nyears>ntimestamp ;
: 9time ( -- str ) now date>9time (time-str) ;
: clock ( -- day-time )  
    now date>9time 4 tail (time-str) ;

New Annotation

Summary:
Author:
Mode:
Body: