From fdf54cf0b11978ec300be74bfdfa4c75a71252ad Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 16 Dec 2020 14:50:11 -0800 Subject: [PATCH] calendar: change >gmt, >local-time to clone. Adding convert-gmt and convert-local-time if you don't want to clone. --- basis/calendar/calendar-docs.factor | 10 ++++---- basis/calendar/calendar.factor | 37 ++++++++++++++++------------- basis/calendar/format/format.factor | 6 ++--- basis/windows/time/time.factor | 4 ++-- core/vocabs/parser/parser.factor | 2 +- extra/time/windows/windows.factor | 3 +-- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/basis/calendar/calendar-docs.factor b/basis/calendar/calendar-docs.factor index 5057209b4e..e2fa95d4e7 100644 --- a/basis/calendar/calendar-docs.factor +++ b/basis/calendar/calendar-docs.factor @@ -272,8 +272,8 @@ HELP: convert-timezone } ; HELP: >local-time -{ $values { "timestamp" timestamp } } -{ $description "Converts the " { $snippet "timestamp" } " to the timezone of your computer." } +{ $values { "timestamp" timestamp } { "timestamp'" timestamp } } +{ $description "Converts the " { $snippet "timestamp" } " to the timezone of your computer, returning a new " { $link timestamp } " instance." } { $examples { $example "USING: accessors calendar kernel prettyprint ;" "now now-gmt >local-time [ gmt-offset>> ] same? ." @@ -282,8 +282,8 @@ HELP: >local-time } ; HELP: >gmt -{ $values { "timestamp" timestamp } } -{ $description "Converts the " { $snippet "timestamp" } " to the GMT timezone." } +{ $values { "timestamp" timestamp } { "timestamp'" timestamp } } +{ $description "Converts the " { $snippet "timestamp" } " to the GMT timezone, returning a new " { $link timestamp } " instance." } { $examples { $example "USING: accessors calendar kernel prettyprint ;" "now >gmt gmt-offset>> hour>> ." @@ -301,7 +301,7 @@ HELP: gmt { $description "Set the time zone to GMT." } { $notes "The time is not converted, if you want that then call " { $link >gmt } "." } ; -{ local-time >local-time gmt >gmt utc >utc convert-timezone } related-words +{ local-time >local-time convert-local-time gmt >gmt convert-gmt utc >utc convert-utc convert-timezone } related-words HELP: duration* { $values { "obj1" object } { "obj2" object } { "obj3" object } } diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index 19af136e1b..7d65f99d21 100644 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -311,35 +311,38 @@ DEFER: time- : convert-timezone ( timestamp duration -- timestamp ) [ over gmt-offset>> time- (time+) ] [ >>gmt-offset ] bi ; -: >local-time ( timestamp -- timestamp ) +: convert-local-time ( timestamp -- timestamp ) gmt-offset-duration convert-timezone ; -: >gmt ( timestamp -- timestamp ) +: convert-gmt ( timestamp -- timestamp ) instant convert-timezone ; -ALIAS: utc gmt -ALIAS: >utc >gmt +: >local-time ( timestamp -- timestamp' ) + clone convert-local-time ; -M: timestamp <=> [ clone >gmt tuple-slots ] compare ; +: >gmt ( timestamp -- timestamp' ) + clone convert-gmt ; -timezone ( timestamp duration -- timestamp' ) + [ clone ] [ convert-timezone ] bi* ; -: same-times? ( timestamp1 timestamp2 quot -- ? ) - [ clone >gmt ] prepose same? ; inline +ALIAS: utc gmt +ALIAS: convert-utc convert-gmt +ALIAS: >utc >gmt -PRIVATE> +M: timestamp <=> [ >gmt tuple-slots ] compare ; : same-year? ( ts1 ts2 -- ? ) - [ slots{ year } ] same-times? ; + [ >gmt slots{ year } ] same? ; : quarter ( timestamp -- [1,4] ) month>> 3 /i 1 + ; inline : same-quarter? ( ts1 ts2 -- ? ) - [ [ year>> ] [ quarter ] bi 2array ] same-times? ; + [ >gmt [ year>> ] [ quarter ] bi 2array ] same? ; : same-month? ( ts1 ts2 -- ? ) - [ slots{ year month } ] same-times? ; + [ >gmt slots{ year month } ] same? ; :: (day-of-year) ( year month day -- n ) month days-until nth day + { @@ -351,7 +354,7 @@ PRIVATE> >date< (day-of-year) ; : same-day? ( ts1 ts2 -- ? ) - [ slots{ year month day } ] same-times? ; + [ >gmt slots{ year month day } ] same? ; : (day-of-week) ( year month day -- n ) ! Zeller Congruence @@ -379,16 +382,16 @@ DEFER: end-of-year } case ; : same-week? ( ts1 ts2 -- ? ) - [ [ year>> ] [ week-number ] bi 2array ] same-times? ; + [ >gmt [ year>> ] [ week-number ] bi 2array ] same? ; : same-hour? ( ts1 ts2 -- ? ) - [ slots{ year month day hour } ] same-times? ; + [ >gmt slots{ year month day hour } ] same? ; : same-minute? ( ts1 ts2 -- ? ) - [ slots{ year month day hour minute } ] same-times? ; + [ >gmt slots{ year month day hour minute } ] same? ; : same-second? ( ts1 ts2 -- ? ) - [ slots{ year month day hour minute second } ] same-times? ; + [ >gmt slots{ year month day hour minute second } ] same? ; > year. ; [ hh:mm:ss ] with-string-writer ; : timestamp>ymdhms ( timestamp -- str ) - [ clone >gmt YYYY-MM-DD " " hh:mm:ss ] with-string-writer ; + [ >gmt YYYY-MM-DD " " hh:mm:ss ] with-string-writer ; : write-gmt-offset-hhmm ( gmt-offset -- ) [ hour>> dup 0 < "-" "+" ? write abs write-00 ] [ mm ] bi ; @@ -185,10 +185,10 @@ ALIAS: timestamp>rfc822 timestamp>rfc2822 ] with-string-writer ; : timestamp>http-string ( timestamp -- str ) - clone >gmt timestamp>rfc2822 ; + >gmt timestamp>rfc2822 ; : timestamp>cookie-string ( timestamp -- str ) - clone >gmt timestamp>rfc1036 ; + >gmt timestamp>rfc1036 ; : write-timestamp ( timestamp -- ) { DAY ", " D " " MONTH " " YYYY " " hh:mm:ss } formatted ; diff --git a/basis/windows/time/time.factor b/basis/windows/time/time.factor index 0b6250a606..dea0e7de40 100644 --- a/basis/windows/time/time.factor +++ b/basis/windows/time/time.factor @@ -22,14 +22,14 @@ IN: windows.time : timestamp>windows-time ( timestamp -- n ) ! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC) - clone >gmt windows-1601 (time-) 10,000,000 * >integer ; + >gmt windows-1601 (time-) 10,000,000 * >integer ; : windows-time>FILETIME ( n -- FILETIME ) [ FILETIME ] dip [ 32 bits >>dwLowDateTime ] [ -32 shift >>dwHighDateTime ] bi ; : timestamp>FILETIME ( timestamp -- FILETIME/f ) - dup [ clone >gmt timestamp>windows-time windows-time>FILETIME ] when ; + dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ; : FILETIME>timestamp ( FILETIME -- timestamp/f ) FILETIME>windows-time windows-time>timestamp ; diff --git a/core/vocabs/parser/parser.factor b/core/vocabs/parser/parser.factor index 408ef633f4..cec4402051 100644 --- a/core/vocabs/parser/parser.factor +++ b/core/vocabs/parser/parser.factor @@ -176,7 +176,7 @@ TUPLE: rename word vocab words ; qualified-vocabs remove! drop ; : with-words ( assoc quot -- ) - [ use-words ] prepose over '[ _ unuse-words ] finally ; inline + '[ use-words @ ] over '[ _ unuse-words ] finally ; inline TUPLE: ambiguous-use-error name words ; diff --git a/extra/time/windows/windows.factor b/extra/time/windows/windows.factor index 0b06382772..6d6b4e7073 100644 --- a/extra/time/windows/windows.factor +++ b/extra/time/windows/windows.factor @@ -5,5 +5,4 @@ windows.kernel32 kernel classes.struct calendar ; IN: time.windows M: windows set-system-time - clone >gmt - timestamp>SYSTEMTIME SetSystemTime win32-error=0/f ; + >gmt timestamp>SYSTEMTIME SetSystemTime win32-error=0/f ; -- 2.34.1