nibbles.ss
#lang scheme/base

(require srfi/19)

(define nps 10000)

(define (current)
  (* nps (current-seconds)))

(define (encode d)
  (let ((t (date->time-utc d)))
    (floor
     (* nps (+ (/ (time-nanosecond t) 1000000) ; nanosecond? <.<
               (time-second t))))))

(define (decode n)
  (define-values (q r) (quotient/remainder n nps))
  (let ((t (make-time 'time-utc q (* (/ r nps) 1000000))))
    (time-utc->date t)))

(provide current encode decode)