]> gitweb.factorcode.org Git - factor.git/commitdiff
Add time vocab that can set system clock time
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 13 Jun 2010 23:30:05 +0000 (18:30 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 14 Jun 2010 00:34:18 +0000 (19:34 -0500)
extra/time/authors.txt [new file with mode: 0644]
extra/time/macosx/authors.txt [new file with mode: 0644]
extra/time/macosx/macosx.factor [new file with mode: 0644]
extra/time/time.factor [new file with mode: 0644]
extra/time/unix/authors.txt [new file with mode: 0644]
extra/time/unix/unix.factor [new file with mode: 0644]

diff --git a/extra/time/authors.txt b/extra/time/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/time/macosx/authors.txt b/extra/time/macosx/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/time/macosx/macosx.factor b/extra/time/macosx/macosx.factor
new file mode 100644 (file)
index 0000000..c28b5c9
--- /dev/null
@@ -0,0 +1,15 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.data calendar calendar.unix classes.struct
+io.files.info.unix.private kernel system time unix unix.time ;
+IN: time.macosx
+
+M: macosx adjust-time-monotonic
+    timestamp>timeval
+    \ timeval <struct>
+    [ adjtime io-error ] keep dup binary-zero? [
+        drop instant
+    ] [
+        timeval>duration since-1970 now time-
+    ] if ;
+
diff --git a/extra/time/time.factor b/extra/time/time.factor
new file mode 100644 (file)
index 0000000..45ba3bc
--- /dev/null
@@ -0,0 +1,7 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: system ;
+IN: time
+
+HOOK: set-time os ( timestamp -- )
+HOOK: adjust-time-monotonic os ( timestamp -- seconds )
diff --git a/extra/time/unix/authors.txt b/extra/time/unix/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/time/unix/unix.factor b/extra/time/unix/unix.factor
new file mode 100644 (file)
index 0000000..ba1bc6e
--- /dev/null
@@ -0,0 +1,9 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: calendar kernel math system time unix unix.time ;
+IN: time.unix
+
+M: unix set-time
+    [ unix-1970 time- duration>microseconds >integer make-timeval ]
+    [ timestamp>timezone ] bi
+    settimeofday io-error ;