}
} ;
+{ time+ time- } related-words
+
HELP: duration>years
{ $values { "duration" duration } { "x" number } }
{ $description "Calculates the length of a duration in years." }
{ $description "Converts the " { $snippet "timestamp" } "'s " { $snippet "gmt-offset" } " to the GMT offset represented by the " { $snippet "duration" } "." }
{ $examples
{ $example "USING: accessors calendar prettyprint ;"
- "now-gmt noon instant -5 >>hour convert-timezone gmt-offset>> hour>> ."
+ "now >gmt noon -5 hours convert-timezone gmt-offset>> hour>> ."
"-5"
}
} ;
{ $description "Converts the " { $snippet "timestamp" } " to the timezone of your computer." }
{ $examples
{ $example "USING: accessors calendar kernel prettyprint ;"
- "now now-gmt >local-time [ gmt-offset>> ] same? ."
+ "now dup clone >gmt >local-time [ gmt-offset>> ] same? ."
"t"
}
} ;
{ local-time >local-time gmt >gmt convert-timezone } related-words
-HELP: time*
+HELP: duration*
{ $values { "obj1" object } { "obj2" object } { "obj3" object } }
-{ $description "Multiplies each time slot of a timestamp or duration by a number and make a new duration from the result. Used in the implementation of " { $link before } "." } ;
-{ time+ time- time* } related-words
+{ $description "Multiplies each time slot of a duration by a number and make a new duration from the result. Used in the implementation of " { $link before } "." } ;
HELP: before
{ $values { "duration" duration } { "-duration" duration } }
}
} ;
-HELP: now-gmt
-{ $values { "timestamp" timestamp } }
-{ $description "Returns the time right now, but in the GMT timezone." } ;
-
-{ now now-gmt } related-words
-
HELP: now
{ $values { "timestamp" timestamp } }
{ $description "Returns the time right now in your computer's timezone." }
{ $subsections time+ }
"Subtracting:"
{ $subsections time- }
-"Element-wise multiplication:"
-{ $subsections time* } ;
+"Multiplying durations:"
+{ $subsections duration* } ;
ARTICLE: "using-durations" "Using durations"
"Creating a duration object:"
HOOK: gmt-offset os ( -- hours minutes seconds )
-HOOK: now-gmt os ( -- timestamp )
+HOOK: now os ( -- timestamp )
TUPLE: duration
{ year real }
: timestamp>micros ( timestamp -- n )
unix-1970 (time-) 1000000 * >integer ;
-: now ( -- timestamp )
- now-gmt gmt-offset-duration [ (time+) ] [ >>gmt-offset ] bi ;
-
: hence ( duration -- timestamp ) now swap time+ ;
: ago ( duration -- timestamp ) now swap time- ;
timeval>seconds seconds ; inline
: timeval>unix-time ( timeval -- timestamp )
- [ unix-1970 ] dip timeval>seconds +second ; inline
+ unix-1970 swap timeval>seconds +second ; inline
: timespec>seconds ( timespec -- seconds )
[ sec>> ] [ nsec>> 1,000,000,000 / ] bi + ; inline
timespec>seconds seconds ; inline
: timespec>unix-time ( timespec -- timestamp )
- [ unix-1970 ] dip timespec>seconds +second ; inline
+ unix-1970 swap timespec>seconds +second ; inline
: get-time ( -- alien )
f time time_t <ref> localtime ; inline
: system-micros ( -- n )
current-timeval timeval>micros ;
-M: unix now-gmt
- current-timeval timeval>unix-time ;
+M: unix now
+ timeval <struct> timezone <struct>
+ [ gettimeofday io-error ] 2keep
+ [ timeval>unix-time dup gmt-offset>> ]
+ [ tz_minuteswest>> 60 /mod [ >>hour ] [ >>minute ] bi* drop ] bi* ;
{ TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
} case neg 60 /mod 0 ;
-M: windows now-gmt
- SYSTEMTIME <struct> [ GetSystemTime ] keep SYSTEMTIME>timestamp ;
+M: windows now
+ SYSTEMTIME <struct> [ GetSystemTime ] keep SYSTEMTIME>timestamp
+ dup gmt-offset>> gmt-offset set-time drop ;
: expire-state ( class -- )
new
- -1/0. now-gmt timestamp>micros [a,b] >>expires
+ -1/0. now timestamp>micros [a,b] >>expires
delete-tuples ;
TUPLE: server-state-manager < filter-responder timeout ;
"<" %
64 random-bits #
"-" %
- now-gmt timestamp>micros #
+ now timestamp>micros #
"@" %
smtp-config get domain>> [ host-name ] unless* %
">" %
! 0x01b21dd213814000L is the number of 100-ns intervals
! between the UUID epoch 1582-10-15 00:00:00 and the
! Unix epoch 1970-01-01 00:00:00.
- now-gmt timestamp>micros 10 * 0x01b21dd213814000 +
+ now timestamp>micros 10 * 0x01b21dd213814000 +
[ -48 shift 0x0fff bitand ]
[ -32 shift 0xffff bitand ]
[ 0xffffffff bitand ]
: ci-run-process ( process -- timestamp os-envs cwd uid euid gid egid out elapsed os-envs' process )
[
[
- now-gmt os-envs current-directory get
+ now os-envs current-directory get
real-user-id effective-user-id
real-group-id effective-group-id
] dip [
: update-key-caps-state ( -- )
read-keyboard keys>>
path binary [
- [ now-gmt unix-1970 time- duration>nanoseconds >integer ]
+ [ now unix-1970 time- duration>nanoseconds >integer ]
[ bit-array>integer ] bi*
[ 8 >be write ] bi@ flush
] with-file-appender ;
Shows the list of connected users."
"who" add-command
-[ drop now-gmt timestamp>rfc822 send-line ]
+[ drop now >gmt timestamp>rfc822 send-line ]
"Syntax: /time
Returns the current GMT time." "time" add-command
TUPLE: irclog-app < dispatcher ;
: irc-link ( channel -- string )
- now-gmt -7 hours convert-timezone >date<
+ now -7 hours convert-timezone >date<
[ unparse 2 tail ] 2dip
"http://bespin.org/~nef/logs/%s/%02s.%02d.%02d"
sprintf ;