📄 mtime.mx
字号:
address MTIMEtimestamp_add_month_interval_wrapcomment "Add months to a timestamp";command timestamp(t:timestamp):timestampaddress MTIMEtimestamp2timestamp;command time_sub_sec_interval(t:daytime,s:lng):daytime address MTIMEtime_sub_sec_interval_wrapcomment "Subtract seconds from a time";command time_add_sec_interval(t:daytime,s:lng):daytime address MTIMEtime_add_sec_interval_wrapcomment "Add seconds to a time";command date_add_month_interval(t:date,s:int):date address MTIMEdate_add_month_interval_wrapcomment "Add months to a date";@-#command int(d:date):int = MTIMEdate_2int;#command int(d:daytime):int = MTIMEdaytime_2int;#command lng(d:timestamp):int = MTIMEtimestamp_2lng;#command lng(d:timezone):lng = MTIMEtzone_2lng;#command int(d:zrule):int = MTIMErule_2int;@malcommand date(:date):dateaddress MTIMEdate2datecomment "generate the nil date";command date(:void):dateaddress MTIMEnil2datecomment "generate the nil date";command local_timezone():lng address MTIMElocal_timezone comment "get the local timezone in seconds";command timezone_local(t:timezone):void address MTIMEtzone_set_local comment "set the local timezone; which is used for printing timestamps";command timezone_local() :timezone address MTIMEtzone_get_local comment "get the local timezone; which is used for printing timestamps";@+ Time/date constructionConstruct temporal values from simple(r) parameters.Out-of range result values are represented by the nil.@malcommand date(s:str):date address MTIMEdate_fromstrcomment "convert the string to a type date value";command date(yr:int, mo:int, day:int):date address MTIMEdate_create comment "creates a date from (year,month,day).";command daytime(s:str):daytimeaddress MTIMEdaytime_fromstrcomment "convert the string to a daytime value.";command daytime(:daytime):daytimeaddress MTIMEdaytime2daytime;command daytime(:lng):daytimeaddress MTIMEsecs2daytime;command daytime(h:int,m:int,s:int,mi:int) :daytime address MTIMEdaytime_create comment "creates a time from (hours,minutes, seconds,milliseconds) parameters.";command timestamp(d:date,dt:daytime,t:timezone) :timestamp address MTIMEtimestamp_create comment "creates a timestamp from (date, daytime,timezone) parameters.";command timestamp(d:date,dt:daytime) :timestamp address MTIMEtimestamp_create_default comment "creates a timestamp from (d,dt) parameters (in the local timezone).";command timestamp(d:date) :timestamp address MTIMEtimestamp_create_from_date comment "creates a timestamp from (d,00:00:00) parameters (in the local timezone).";command rule(s:str):zruleaddress MTIMErule_fromstrcomment "create a rule from a string.";command rule (mo:int,d:int,wkday:int,mi:int) :zrule address MTIMErule_create comment "create a DST start/end date rule.";command timezone(s:str):timezone address MTIMEtzone_fromstrcomment "Convert the string to a timezone.";command timezone(s:int):timezone address MTIMEtzone_createcomment "Convert the int to a timezone.";command timezone(s:lng):timezone address MTIMEtzone_createcomment "Convert the int to a timezone.";command timezone(mi:int,s:zrule,erule:zrule):timezone address MTIMEtzone_create_dst comment "create a timezone as an hour difference from GMT and a DST.";@- Time/date decomposition@TThere are routines that decompose a date and routines that decompose a daytime.For decomposing a timestamp, there are routines that decompose it in a dateand daytime. The bulk variants are also provided to simplify codegeneration for SQL and to improve speed.@malcommand year(d:date) :int address MTIMEdate_extract_year comment "extracts year from date (nonzero value between -5867411 and +5867411).";command year(d:bat[:any_1,:date]):bat[:any_1,:int]address MTIMEdate_extract_year_bulk;command month(d:date) :int address MTIMEdate_extract_month comment "extracts month from date";command month(d:bat[:any_1,:date]):bat[:any_1,:int]address MTIMEdate_extract_month_bulk;command day(d:date) :int address MTIMEdate_extract_day comment "extracts day from date ";command day(d:bat[:any_1,:date]):bat[:any_1,:int]address MTIMEdate_extract_day_bulk;command hours(h:daytime) :int address MTIMEdaytime_extract_hours comment "extracts hour from daytime";command hours(d:bat[:any_1,:date]):bat[:any_1,:int]address MTIMEdaytime_extract_hours_bulk;command minutes(d:daytime) :int address MTIMEdaytime_extract_minutes comment "extracts minutes from daytime";command minutes(d:bat[:any_1,:date]):bat[:any_1,:int]address MTIMEdaytime_extract_minutes_bulk;command seconds(d:daytime) :int address MTIMEdaytime_extract_seconds comment "extracts seconds from daytime";command seconds(d:bat[:any_1,:date]):bat[:any_1,:int]address MTIMEdaytime_extract_seconds_bulk;command milliseconds(d:daytime) :int address MTIMEdaytime_extract_milliseconds comment "extracts milliseconds from daytime";command milliseconds(d:bat[:any_1,:date]):bat[:any_1,:int]address MTIMEdaytime_extract_milliseconds_bulk;command daytime(t:timestamp) :daytime address MTIMEtimestamp_extract_daytime_default comment "extracts daytime from timestamp in the local timezone.";command daytime(t:timestamp, v:timezone) :daytime address MTIMEtimestamp_extract_daytime comment "extracts daytime from timestamp in a specific timezone.";command date(t:timestamp) :date address MTIMEtimestamp_extract_date_default comment "extracts date from timestamp in the local timezone.";command date(t:timestamp,v:timezone) :date address MTIMEtimestamp_extract_date comment "extracts date from timestamp in a specific timezone.";command setTimezone(name:str):timezone address MTIMEtimezonecomment "Test and set the timezone.";command start_dst(t:timezone) :zrule address MTIMEtzone_extract_start comment "extract rule that determines start of DST from timezone.";command end_dst(t:timezone) :zrule address MTIMEtzone_extract_end comment "extract rule that determines end of DST from timezone.";command minutes(t:timezone) :int address MTIMEtzone_extract_minutes comment "extract number of minutes that time zone is offset wrt GMT.";# rulecommand month(t:zrule) :int address MTIMErule_extract_month comment "extract month from rule.";command day(t:zrule) :int address MTIMErule_extract_day comment "extract day from rule.";command weekday(t:zrule) :int address MTIMErule_extract_weekday comment "extract weekday from rule.";command minutes(t:zrule) :int address MTIMErule_extract_minutes comment "extract minutes from rule.";@+ Time/date arithmetic@TWe choose to represent intervals of time as numbers of days (as int, a 32-bits integer)and numbers of milliseconds (as lng, a 64-bits integer). Using standard integer typesfacilitates computation with these amounts of time (you can use all normal integerarithmetic operators).Arithmetic overflow returns the nil atom (no error messages). For all commands inthis modules it holds that if one of the parameters is nil, the result is also nil(nil has the don't know semantics in MIL).@malcommand addyears(value:date, years:int) :date address MTIMEdate_addyears comment "returns the date after a number of years (possibly negative).";command addmonths(value:date, months:int) :date address MTIMEdate_addmonths comment "returns the date after a number of months (possibly negative).";command adddays(value:date, days:int) :date address MTIMEdate_adddays comment "returns the date after a number of days (possibly negative).";command diff(val1:date, val2:date) :int address MTIMEdate_diff comment "returns the number of days between 'val1' and 'val2'.";command dayofyear(d:date) :int address MTIMEdate_extract_dayofyear comment "Returns N where d is the Nth day of the year (january 1 returns 1)";command weekofyear(d:date) :int address MTIMEdate_extract_weekofyear comment "Returns the week number in the year.";command dayofweek(d:date) :int address MTIMEdate_extract_dayofweek comment "Returns the current day of the week where 1=sunday, .., 7=saturday";command add(v:timestamp, msecs:lng) :timestamp address MTIMEtimestamp_add comment "returns the timestamp that comes 'msecs' (possibly negative) after 'value'.";command diff(val1:timestamp, val2:timestamp) :lng address MTIMEtimestamp_diff comment "returns the number of milliseconds between 'val1' and 'val2'.";command dst(t:timestamp,v:timezone) :bit address MTIMEtimestamp_inside_dst comment "return whether DST holds in the timezone at a certain point of time.";command compute(r:zrule, year:int) :date address MTIMEcompute_rule_foryear comment "compute the date from a rule in a given year";@- Day and month namesOne day we should introduce the concept of locale, and hook here.@malcommand monthnum(month:str) :int address MTIMEmonth_from_str comment "Returns month number [1-12] from a string or nil if does not match any.";command monthname(month:int) :str address MTIMEmonth_to_str comment "Returns month name from a number between [1-12], str(nil) otherwise.";command daynum(day:str) :int address MTIMEday_from_str comment "Returns number of day [1-7] from a string or nil if does not match any.";command dayname(day:int) :str address MTIMEday_to_str comment "Returns day name from a number between [1-7], str(nil) otherwise.";command time_synonyms(allow:bit) address MTIMEsynonyms comment "Allow synonyms for the parse format of date/timestamp.";command olddate (format:str) :date address MTIMEolddate comment "create a date from the old instant format.";command oldduration(format:str) :int address MTIMEoldduration comment "parse the old duration format and return an (estimated) number of days.";@+ UtilitiesThe Monet V4 procs are converted into functions.@malcommand msecs(d:int,h:int,m:int,s:int,ms:int):lngaddress MTIMEmsecscomment "convert date components to milliseconds";command daytime(h:int):daytime address MTIMEdaytime1comment "default time with zeroed components";command daytime(h:int,m:int):daytime address MTIMEdaytime2comment "default time with zeroed components";command daytime(h:int,m:int,s:int):daytime address MTIMEdaytime3comment "default time with zeroed components";command current_timestamp():timestampaddress MTIMEcurrent_timestamp;command current_date():dateaddress MTIMEcurrent_date;command current_time():daytimeaddress MTIMEcurrent_time;command year(t:timestamp):int address MTIMEtimestamp_year;command month(t:timestamp):intaddress MTIMEtimestamp_month;command day(t:timestamp):intaddress MTIMEtimestamp_day;command hours(t:timestamp):intaddress MTIMEtimestamp_hours;command minutes(t:timestamp):intaddress MTIMEtimestamp_minutes;command seconds(t:timestamp):intaddress MTIMEtimestamp_seconds;command milliseconds(t:timestamp):intaddress MTIMEtimestamp_milliseconds;command year(months:int):intaddress MTIMEsql_year;command month(months:int):intaddress MTIMEsql_month;command day(secs:lng):intaddress MTIMEsql_day;command hours(secs:lng):intaddress MTIMEsql_hours;command minutes(secs:lng):intaddress MTIMEsql_minutes;command seconds(secs:lng):intaddress MTIMEsql_seconds;command msec():lng address MTIMEmseccomment "get time of day in msec since 1-1-1970.";@{@+ Prelude sectionUpon intialization of the time module, we have toinitialize some variables, e.g. nils and the box with predefinedconstants.These actions are captured in a single function activated directly afterparsing of the signatures. @malcommand prelude() :voidaddress MTIMEprelude;command epilogue() :voidaddress MTIMEepilogue;mtime.prelude();module calc;command date(s:str):date address MTIMEdate_fromstr;command date(d:date):date address MTIMEdate_date;command date(t:timestamp) :date address MTIMEtimestamp_extract_date_default;command timestamp(s:str):timestamp address MTIMEtimestamp_fromstr;command timestamp(t:timestamp):timestamp address MTIMEtimestamp2timestamp;command timestamp(d:date) :timestamp address MTIMEtimestamp_create_from_date;command daytime(s:str):daytime address MTIMEdaytime_fromstr;command daytime(d:daytime):daytime address MTIMEdaytime2daytime;command daytime(s:lng):daytime address MTIMEsecs2daytime;command daytime(t:timestamp) :daytime address MTIMEtimestamp_extract_daytime_default;@* Implementation@+ Atoms@- dateInternally, we store date as the (possibly negative) number ofdays since the start of the calendar. Oddly, since I (later) learnedthat the year 0 did no exist, this defines the start of the calendar tobe Jan 1 of the year -1 (in other words, a -- positive -- year componentof a date is equal to the number of years that have passed since the startof the calendar).@h#ifndef _MONETTIME_H_#define _MONETTIME_H_#include <gdk.h>#include "mal.h"#include "mal_exception.h"#ifdef WIN32#ifndef LIBMTIME#define mtime_export extern __declspec(dllimport)#else#define mtime_export extern __declspec(dllexport)#endif#else#define mtime_export extern#endif#if TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# if HAVE_SYS_TIME_H# include <sys/time.h># else# include <time.h># endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -