all repos — min @ aef97d6a1a2d52209d1e6fbc9de94e511c2a39d4

A small but practical concatenative programming language.

Enhanced and documented time module.
h3rald h3rald@h3rald.com
Sat, 08 Jul 2017 15:18:36 +0200
commit

aef97d6a1a2d52209d1e6fbc9de94e511c2a39d4

parent

966cf2c24f7962d590c7348eca71e6dff2593727

M lib/min_time.nimlib/min_time.nim

@@ -37,8 +37,27 @@ info.qVal.add @["yearday".newSym, tinfo.yearday.newVal].newVal(i.scope)

info.qVal.add @["hour".newSym, tinfo.hour.newVal].newVal(i.scope) info.qVal.add @["minute".newSym, tinfo.minute.newVal].newVal(i.scope) info.qVal.add @["second".newSym, tinfo.second.newVal].newVal(i.scope) + info.qVal.add @["dst".newSym, tinfo.isDST.newVal].newVal(i.scope) + info.qVal.add @["timezone".newSym, tinfo.timezone.newVal].newVal(i.scope) i.push info + def.symbol("to-timestamp") do (i: In): + let vals = i.expect("dict") + let dict = vals[0] + try: + let year = dict.dget("year".newVal).intVal.int + let month = dict.dget("month".newVal).intVal.int - 1 + let monthday = dict.dget("day".newVal).intVal.int + let hour = dict.dget("hour".newVal).intVal.int + let minute = dict.dget("minute".newVal).intVal.int + let second = dict.dget("second".newVal).intVal.int + let dst = dict.dget("dst".newVal).boolVal + let timezone = dict.dget("timezone".newVal).intVal.int + let tinfo = TimeInfo(year: year, month: Month(month), monthday: monthday, hour: hour, minute: minute, second: second, isDST: dst, timezone: timezone) + i.push tinfo.toTime.toSeconds.int.newVal + except: + raiseInvalid("An invalid timeinfo dictionary was provided.") + def.symbol("datetime") do (i: In): let vals = i.expect("num") let t = vals[0]

@@ -47,7 +66,7 @@ if t.kind == minInt:

time = t.intVal.fromSeconds else: time = t.floatVal.fromSeconds - i.push time.getLocalTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'").newVal + i.push time.getGMTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'").newVal def.symbol("tformat") do (i: In): let vals = i.expect("string", "num")
M min.vimmin.vim

@@ -11,7 +11,7 @@

setl iskeyword=@,36-39,+,-,/,*,.,:,~,!,48-57,60-65,94-95,192-255 setl iskeyword+=^ -syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append args ask atime bind bool boolean? call call! capitalize case cd chmod choose clear-stack cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define delete dget dictionary? dip dir? dirname div dprint dprint! dset dup encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get gets get-env get-stack hardlink harvest hidden? id if import in? indent indexof info insert int integer? interpolate interval io join keep keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map map-reduce match md5 mkdir mod module module-symbols module-sigils mtime mv newline nip not notice now num number? odd? opts os over partition password pick pop popd pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define random raise reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sip size sleep slice sort source split spread stack startup stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unquote uppercase unzip values version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append args ask atime bind bool boolean? call call! capitalize case cd chmod choose clear-stack cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define delete dget dictionary? dip dir? dirname div dprint dprint! dset dup encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get gets get-env get-stack hardlink harvest hidden? id if import in? indent indexof info insert int integer? interpolate interval io join keep keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map map-reduce match md5 mkdir mod module module-symbols module-sigils mtime mv newline nip not notice now num number? odd? opts os over partition password pick pop popd pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define random raise reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sip size sleep slice sort source split spread stack startup stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json to-timestamp try unquote uppercase unzip values version warn when which while with xor zip syntax match minDefaultSigil ;\<[:@'~!$%&$=<>#^*#+/]; contained
M site/contents/_includes/_defs_.mdsite/contents/_includes/_defs_.md

@@ -8,6 +8,7 @@ {{2 => [<sub>2</sub>](class:kwd)}}

{{3 => [<sub>3</sub>](class:kwd)}} {{4 => [<sub>4</sub>](class:kwd)}} {{e => [err](class:kwd)}} +{{tinfo => [tinfo](class:kwd)}} {{d => [dict](class:kwd)}} {{d1 => [dict<sub>1</sub>](class:kwd)}} {{d2 => [dict<sub>2</sub>](class:kwd)}}
M site/contents/_includes/_reference-time.mdsite/contents/_includes/_reference-time.md

@@ -1,1 +1,25 @@

-... +{@ _defs_.md || 0 @} + +{#op||now||{{null}}||{{flt}}|| +Returns the current time as Unix timestamp with microseconds. #} + +{#op||timestamp||{{null}}||{{i}}|| +Returns the current time as Unix timestamp. #} + +{#op||timeinfo||{{i}}||{{tinfo}}|| +Returns a timeinfo dictionary from timestamp {{i}}. #} + +{#op||to-timestamp||{{tinfo}}||{{i}}|| +Converts the timeinfo dictionary {{tinfo}} to the corresponding Unix timestamp. #} + +{#op||datetime||{{i}}||{{s}}|| +Returns an ISO 8601 string representing the combined date and time in UTC of timestamp {{i}}. #} + + +{#op||tformat||{{i}} {{s}}||{{s}}|| +> Formats timestamp {{i}} using string {{s}}. +> +> > %tip% +> > Tip +> > +> > For information on special characters in the format string, see the [format](https://nim-lang.org/docs/times.html#format,TimeInfo,string) nim method. #}
M site/contents/_includes/_reference.mdsite/contents/_includes/_reference.md

@@ -51,6 +51,21 @@ {{q}}

: A quotation (also expressed as parenthesis enclosing other values). {{d}} : A dictionary value. +{{tinfo}} +: A timeinfo dictionary: + <pre><code>( + (year 2017) + (month 7) + (day 8) + (weekday 6) + (yearday 188) + (hour 15) + (minute 16) + (second 25) + (dst true) + (timezone -3600) + ) + </code></pre> {{e}} : An error dictionary: <pre><code>(
M tests/sys.mintests/sys.min

@@ -63,9 +63,7 @@ . ls "test.zip" zip . ls (. "test.zip") => "/" join in?) assert

("test.zip" "extracted" unzip "extracted" ls "extracted/test1.txt" in?) assert - "extracted" ls 'rm foreach - . ls 'rm foreach - .. cd + .. cd ("systest" rmdir . ls (. "systest") => "/" join in? false ==) assert

@@ -73,4 +71,4 @@

report clear-stack - "systest" rmdir+ "systest" rmdir
M tests/time.mintests/time.min

@@ -7,11 +7,15 @@ (timestamp 1464951736 >) assert

(now 1464951736 >) assert - (1464951736 datetime "2016-06-03T13:02:16Z" ==) assert + (1464951736 datetime "2016-06-03T11:02:16Z" ==) assert (1464951736 "yy-MM-dd" tformat "16-06-03" ==) assert + + (1464951736 timeinfo to-timestamp puts 1464951736 ==) assert (1464951736 timeinfo 'second dget 16 ==) assert + (1464951736 timeinfo 'timezone dget -3600 ==) assert + report - clear-stack+ clear-stack