1. Yasir Arsanukaev
  2. scheme-bert

Commits

Yasir M. Arsanukaev  committed ed88711

Time conversion implemented, associated test supplied.

  • Participants
  • Parent commits 692f6d0
  • Branches default

Comments (0)

Files changed (2)

File README.markdown

View file
 * `#t`
 * `#f`
 * `hashtable?`
+* `time?`
 
 TODO
 ----
 Implement encoding of these objects:
 
 * `flonum?`
-* `time?`
 * `pregexp?`
 
 

File src/encode.ss

View file
         (rnrs arithmetic bitwise)
         (rnrs arithmetic flonums)
         (mzlib pregexp)
-        (erl-ext-types))
+        (erl-ext-types)
+        (srfi :19))
 
 
 (define (map/and proc lst)
      (vector 'bert 'false))
     ((eqv? obj 'nil)
      (vector 'bert 'nil))
+    ((time? obj)
+     (let ((t (time-second obj)))
+       (vector 'bert 
+               'time 
+               (div t 1000000) 
+               (mod t 1000000)
+               (div (time-nanosecond obj) 1000))))
     (else obj)))
 
 (define (encode obj)
         #t
         (error "test-2" "failed"))))
 
+(define (test-3)
+  ; {bert, time, erlang:now()}
+  (if (equal? (encode (make-time time-utc 234389000 1281880551))
+              (u8-list->bytevector '(131 104 5 100 0 4 98 101 114 116 100 0 4 116 105 109 101 98 0 0 5 1 98 0 13 111 167 98 0 3 147 149)))
+      #t
+      (error "test-3" "failed")))
+
 (define (tests)
-  (and (test-1) (test-2)))
+  (and (test-1) (test-2) (test-3)))