228 lines
17 KiB
Plaintext
228 lines
17 KiB
Plaintext
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="generator" content="TempleOS V5.03">
|
||
|
<meta name="viewport" content="width=device-width">
|
||
|
<link rel="stylesheet" href="/style/templeos.css">
|
||
|
<script src="/script/templeos.js"></script>
|
||
|
<style type="text/css">
|
||
|
.cF0{color:#000000;background-color:#ffffff;}
|
||
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
||
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
||
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
||
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
||
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
||
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
||
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
||
|
.cF8{color:#555555;background-color:#ffffff;}
|
||
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
||
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
||
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
||
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
||
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
||
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
||
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<pre id="content">
|
||
|
<a name="l1"></a><span class=cF2>//See </span><a href="/Wb/Doc/TimeDate.DD.HTML#l1"><span class=cF4>::/Doc/TimeDate.DD</span></a><span class=cF0>
|
||
|
<a name="l2"></a>
|
||
|
<a name="l3"></a></span><span class=cF9>U16</span><span class=cF0> </span><span class=cFB>mon_start_days1</span><span class=cF0>[12]={
|
||
|
<a name="l4"></a>0,31,59,90,120,151,181,212,243,273,304,334};
|
||
|
<a name="l5"></a></span><span class=cF9>U16</span><span class=cF0> </span><span class=cFB>mon_start_days2</span><span class=cF0>[12]={
|
||
|
<a name="l6"></a>0,31,60,91,121,152,182,213,244,274,305,335};
|
||
|
<a name="l7"></a>
|
||
|
<a name="l8"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>YearStartDate</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> year)
|
||
|
<a name="l9"></a>{</span><span class=cF2>//32-bit day since AD 0, given year number.</span><span class=cF0>
|
||
|
<a name="l10"></a> </span><span class=cF9>I64</span><span class=cF0> y1=year-1,yd4000=y1/4000,yd400=y1/400,yd100=y1/100,yd4=y1/4;
|
||
|
<a name="l11"></a> </span><span class=cF1>return</span><span class=cF0> year*365+yd4-yd100+yd400-yd4000;
|
||
|
<a name="l12"></a>}
|
||
|
<a name="l13"></a>
|
||
|
<a name="l14"></a></span><span class=cF9>CDate</span><span class=cF0> </span><span class=cF5>Struct2Date</span><span class=cF0>(</span><span class=cF9>CDateStruct</span><span class=cF0> *_ds)
|
||
|
<a name="l15"></a>{</span><span class=cF2>//Cvt CDateStruct to CDate.</span><span class=cF0>
|
||
|
<a name="l16"></a> </span><span class=cF9>CDate</span><span class=cF0> cdt;
|
||
|
<a name="l17"></a> </span><span class=cF9>I64</span><span class=cF0> i1,i2;
|
||
|
<a name="l18"></a> i1=</span><span class=cF5>YearStartDate</span><span class=cF0>(_ds->year);
|
||
|
<a name="l19"></a> i2=</span><span class=cF5>YearStartDate</span><span class=cF0>(_ds->year+1);
|
||
|
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (i2-i1==365)
|
||
|
<a name="l21"></a> i1+=</span><span class=cFB>mon_start_days1</span><span class=cF0>[_ds->mon-1];
|
||
|
<a name="l22"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l23"></a> i1+=</span><span class=cFB>mon_start_days2</span><span class=cF0>[_ds->mon-1];
|
||
|
<a name="l24"></a> cdt.date=i1+_ds->day_of_mon-1;
|
||
|
<a name="l25"></a> cdt.time=(_ds->sec10000+100*</span><span class=cF7>(</span><span class=cF0>_ds->sec100+100*(_ds->sec
|
||
|
<a name="l26"></a> +60*</span><span class=cF7>(</span><span class=cF0>_ds->min+60*_ds->hour</span><span class=cF7>)</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0>)<<21/(15*15*3*625);
|
||
|
<a name="l27"></a> </span><span class=cF1>return</span><span class=cF0> cdt;
|
||
|
<a name="l28"></a>}
|
||
|
<a name="l29"></a>
|
||
|
<a name="l30"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DayOfWeek</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> i)
|
||
|
<a name="l31"></a>{</span><span class=cF2>//Day of week, given 32-bit day since AD 0.</span><span class=cF0>
|
||
|
<a name="l32"></a> i+=</span><span class=cF3>CDATE_BASE_DAY_OF_WEEK</span><span class=cF0>;
|
||
|
<a name="l33"></a> </span><span class=cF1>if</span><span class=cF0> (i>=0)
|
||
|
<a name="l34"></a> </span><span class=cF1>return</span><span class=cF0> i % 7;
|
||
|
<a name="l35"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l36"></a> </span><span class=cF1>return</span><span class=cF0> 6-(6-i)%7;
|
||
|
<a name="l37"></a>}
|
||
|
<a name="l38"></a>
|
||
|
<a name="l39"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Date2Struct</span><span class=cF0>(</span><span class=cF9>CDateStruct</span><span class=cF0> *_ds,</span><span class=cF9>CDate</span><span class=cF0> cdt)
|
||
|
<a name="l40"></a>{</span><span class=cF2>//Cvt CDate to CDateStruct.</span><span class=cF0>
|
||
|
<a name="l41"></a> </span><span class=cF9>I64</span><span class=cF0> i,k,date=cdt.date;
|
||
|
<a name="l42"></a> _ds->day_of_week=</span><span class=cF5>DayOfWeek</span><span class=cF0>(date);
|
||
|
<a name="l43"></a> _ds->year=(date+1)*100000/</span><span class=cF3>CDATE_YEAR_DAYS_INT</span><span class=cF0>;
|
||
|
<a name="l44"></a> i=</span><span class=cF5>YearStartDate</span><span class=cF0>(_ds->year);
|
||
|
<a name="l45"></a> </span><span class=cF1>while</span><span class=cF0> (i>date) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l46"></a> _ds->year--;
|
||
|
<a name="l47"></a> i=</span><span class=cF5>YearStartDate</span><span class=cF0>(_ds->year);
|
||
|
<a name="l48"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l49"></a> date-=i;
|
||
|
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>YearStartDate</span><span class=cF7>(</span><span class=cF0>_ds->year+1</span><span class=cF7>)</span><span class=cF0>-i==365) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l51"></a> k=0;
|
||
|
<a name="l52"></a> </span><span class=cF1>while</span><span class=cF0> (date>=</span><span class=cFB>mon_start_days1</span><span class=cF0>[k+1] && k<11)
|
||
|
<a name="l53"></a> k++;
|
||
|
<a name="l54"></a> date-=</span><span class=cFB>mon_start_days1</span><span class=cF0>[k];
|
||
|
<a name="l55"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l56"></a> k=0;
|
||
|
<a name="l57"></a> </span><span class=cF1>while</span><span class=cF0> (date>=</span><span class=cFB>mon_start_days2</span><span class=cF0>[k+1] && k<11)
|
||
|
<a name="l58"></a> k++;
|
||
|
<a name="l59"></a> date-=</span><span class=cFB>mon_start_days2</span><span class=cF0>[k];
|
||
|
<a name="l60"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l61"></a> _ds->mon=k+1;
|
||
|
<a name="l62"></a> _ds->day_of_mon=date+1;
|
||
|
<a name="l63"></a> k=(625*15*15*3*cdt.time)>>21+1;
|
||
|
<a name="l64"></a> _ds->sec10000=</span><span class=cF5>ModU64</span><span class=cF0>(&k,100);
|
||
|
<a name="l65"></a> _ds->sec100=</span><span class=cF5>ModU64</span><span class=cF0>(&k,100);
|
||
|
<a name="l66"></a> _ds->sec=</span><span class=cF5>ModU64</span><span class=cF0>(&k,60);
|
||
|
<a name="l67"></a> _ds->min=</span><span class=cF5>ModU64</span><span class=cF0>(&k,60);
|
||
|
<a name="l68"></a> _ds->hour =k;
|
||
|
<a name="l69"></a>}
|
||
|
<a name="l70"></a>
|
||
|
<a name="l71"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>FirstDayOfMon</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> i)
|
||
|
<a name="l72"></a>{</span><span class=cF2>//First day of month, given 32-bit day since AD 0.</span><span class=cF0>
|
||
|
<a name="l73"></a> </span><span class=cF9>CDateStruct</span><span class=cF0> ds;
|
||
|
<a name="l74"></a> </span><span class=cF9>CDate</span><span class=cF0> cdt=0;
|
||
|
<a name="l75"></a> cdt.date=i;
|
||
|
<a name="l76"></a> </span><span class=cF5>Date2Struct</span><span class=cF0>(&ds,cdt);
|
||
|
<a name="l77"></a> ds.day_of_mon=1;
|
||
|
<a name="l78"></a> cdt=</span><span class=cF5>Struct2Date</span><span class=cF0>(&ds);
|
||
|
<a name="l79"></a> </span><span class=cF1>return</span><span class=cF0> cdt.date;
|
||
|
<a name="l80"></a>}
|
||
|
<a name="l81"></a>
|
||
|
<a name="l82"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>LastDayOfMon</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> i)
|
||
|
<a name="l83"></a>{</span><span class=cF2>//Last day of month, given 32-bit day since AD 0.</span><span class=cF0>
|
||
|
<a name="l84"></a> </span><span class=cF9>CDateStruct</span><span class=cF0> ds;
|
||
|
<a name="l85"></a> </span><span class=cF9>CDate</span><span class=cF0> cdt=0;
|
||
|
<a name="l86"></a> cdt.date=i;
|
||
|
<a name="l87"></a> </span><span class=cF5>Date2Struct</span><span class=cF0>(&ds,cdt);
|
||
|
<a name="l88"></a> ds.mon++;
|
||
|
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (ds.mon==13) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l90"></a> ds.mon=0;
|
||
|
<a name="l91"></a> ds.year++;
|
||
|
<a name="l92"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l93"></a> ds.day_of_mon=1;
|
||
|
<a name="l94"></a> cdt=</span><span class=cF5>Struct2Date</span><span class=cF0>(&ds);
|
||
|
<a name="l95"></a> </span><span class=cF1>return</span><span class=cF0> cdt.date-1;
|
||
|
<a name="l96"></a>}
|
||
|
<a name="l97"></a>
|
||
|
<a name="l98"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>FirstDayOfYear</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> i)
|
||
|
<a name="l99"></a>{</span><span class=cF2>//First day of year, given 32-bit day since AD 0.</span><span class=cF0>
|
||
|
<a name="l100"></a> </span><span class=cF9>CDateStruct</span><span class=cF0> ds;
|
||
|
<a name="l101"></a> </span><span class=cF9>CDate</span><span class=cF0> cdt=0;
|
||
|
<a name="l102"></a> cdt.date=i;
|
||
|
<a name="l103"></a> </span><span class=cF5>Date2Struct</span><span class=cF0>(&ds,cdt);
|
||
|
<a name="l104"></a> ds.day_of_mon=1;
|
||
|
<a name="l105"></a> ds.mon=1;
|
||
|
<a name="l106"></a> cdt=</span><span class=cF5>Struct2Date</span><span class=cF0>(&ds);
|
||
|
<a name="l107"></a> </span><span class=cF1>return</span><span class=cF0> cdt.date;
|
||
|
<a name="l108"></a>}
|
||
|
<a name="l109"></a>
|
||
|
<a name="l110"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>LastDayOfYear</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> i)
|
||
|
<a name="l111"></a>{</span><span class=cF2>//Last day of year, given 32-bit day since AD 0.</span><span class=cF0>
|
||
|
<a name="l112"></a> </span><span class=cF9>CDateStruct</span><span class=cF0> ds;
|
||
|
<a name="l113"></a> </span><span class=cF9>CDate</span><span class=cF0> cdt=0;
|
||
|
<a name="l114"></a> cdt.date=i;
|
||
|
<a name="l115"></a> </span><span class=cF5>Date2Struct</span><span class=cF0>(&ds,cdt);
|
||
|
<a name="l116"></a> ds.day_of_mon=1;
|
||
|
<a name="l117"></a> ds.mon=1;
|
||
|
<a name="l118"></a> ds.year++;
|
||
|
<a name="l119"></a> cdt=</span><span class=cF5>Struct2Date</span><span class=cF0>(&ds);
|
||
|
<a name="l120"></a> </span><span class=cF1>return</span><span class=cF0> cdt.date-1;
|
||
|
<a name="l121"></a>}
|
||
|
<a name="l122"></a>
|
||
|
<a name="l123"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>Bcd2Bin</span><span class=cF0>(</span><span class=cF9>U64</span><span class=cF0> b)
|
||
|
<a name="l124"></a>{
|
||
|
<a name="l125"></a> </span><span class=cF9>I64</span><span class=cF0> i,res=0;
|
||
|
<a name="l126"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<16;i++) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l127"></a> res=res*10+b>>60;
|
||
|
<a name="l128"></a> b<<=4;
|
||
|
<a name="l129"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l130"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
||
|
<a name="l131"></a>}
|
||
|
<a name="l132"></a>
|
||
|
<a name="l133"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>NowDateTimeStruct</span><span class=cF0>(</span><span class=cF9>CDateStruct</span><span class=cF0> *_ds)
|
||
|
<a name="l134"></a>{
|
||
|
<a name="l135"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
||
|
<a name="l136"></a> </span><span class=cF1>U8</span><span class=cF0> *b=_ds;
|
||
|
<a name="l137"></a> </span><span class=cF1>Bool</span><span class=cF0> is_bcd;
|
||
|
<a name="l138"></a>
|
||
|
<a name="l139"></a> </span><span class=cF5>MemSet</span><span class=cF0>(_ds,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDateStruct</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l140"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
||
|
<a name="l141"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
||
|
<a name="l142"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SYS_DATE</span><span class=cF0>],0</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l143"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
|
||
|
<a name="l144"></a>
|
||
|
<a name="l145"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,0x0A);
|
||
|
<a name="l146"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l147"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>0x71</span><span class=cF7>)</span><span class=cF0> & 0x80)
|
||
|
<a name="l148"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
|
||
|
<a name="l149"></a>
|
||
|
<a name="l150"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,0);
|
||
|
<a name="l151"></a> b[2]=</span><span class=cF5>InU8</span><span class=cF0>(0x71);
|
||
|
<a name="l152"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,2);
|
||
|
<a name="l153"></a> b[3]=</span><span class=cF5>InU8</span><span class=cF0>(0x71);
|
||
|
<a name="l154"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,4);
|
||
|
<a name="l155"></a> b[4]=</span><span class=cF5>InU8</span><span class=cF0>(0x71);
|
||
|
<a name="l156"></a>
|
||
|
<a name="l157"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,6);
|
||
|
<a name="l158"></a> b[5]=</span><span class=cF5>InU8</span><span class=cF0>(0x71);
|
||
|
<a name="l159"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,7);
|
||
|
<a name="l160"></a> b[6]=</span><span class=cF5>InU8</span><span class=cF0>(0x71);
|
||
|
<a name="l161"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,8);
|
||
|
<a name="l162"></a> b[7]=</span><span class=cF5>InU8</span><span class=cF0>(0x71);
|
||
|
<a name="l163"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,9);
|
||
|
<a name="l164"></a> b[8]=</span><span class=cF5>InU8</span><span class=cF0>(0x71);
|
||
|
<a name="l165"></a>
|
||
|
<a name="l166"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,0x0A);
|
||
|
<a name="l167"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>0x71</span><span class=cF7>)</span><span class=cF0> & 0x80);
|
||
|
<a name="l168"></a>
|
||
|
<a name="l169"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x70,0x0B);
|
||
|
<a name="l170"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>0x71</span><span class=cF7>)</span><span class=cF0> & 4)
|
||
|
<a name="l171"></a> is_bcd=</span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l172"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l173"></a> is_bcd=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l174"></a>
|
||
|
<a name="l175"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SYS_DATE</span><span class=cF0>],0);
|
||
|
<a name="l176"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
||
|
<a name="l177"></a> </span><span class=cF1>if</span><span class=cF0> (is_bcd)
|
||
|
<a name="l178"></a> </span><span class=cF1>for</span><span class=cF0> (i=2;i<9;i++)
|
||
|
<a name="l179"></a> b[i]=</span><span class=cFD>Bcd2Bin</span><span class=cF0>(b[i]);
|
||
|
<a name="l180"></a>
|
||
|
<a name="l181"></a> </span><span class=cF1>if</span><span class=cF0> (_ds->year>255) _ds->year=255;
|
||
|
<a name="l182"></a> _ds->year+=2000;
|
||
|
<a name="l183"></a> </span><span class=cF1>if</span><span class=cF0> (_ds->mon>12) _ds->mon=12;
|
||
|
<a name="l184"></a> </span><span class=cF1>if</span><span class=cF0> (_ds->day_of_mon>31) _ds->day_of_mon=31;
|
||
|
<a name="l185"></a> </span><span class=cF1>if</span><span class=cF0> (_ds->day_of_week>6) _ds->day_of_week=6;
|
||
|
<a name="l186"></a> </span><span class=cF1>if</span><span class=cF0> (_ds->hour>23) _ds->hour=23;
|
||
|
<a name="l187"></a> </span><span class=cF1>if</span><span class=cF0> (_ds->min>59) _ds->min=59;
|
||
|
<a name="l188"></a> </span><span class=cF1>if</span><span class=cF0> (_ds->sec>59) _ds->sec=59;
|
||
|
<a name="l189"></a>}
|
||
|
<a name="l190"></a>
|
||
|
<a name="l191"></a></span><span class=cF9>CDate</span><span class=cF0> </span><span class=cF5>Now</span><span class=cF0>()
|
||
|
<a name="l192"></a>{</span><span class=cF2>//Current datetime.</span><span class=cF0>
|
||
|
<a name="l193"></a> </span><span class=cF9>CDateStruct</span><span class=cF0> ds;
|
||
|
<a name="l194"></a> </span><span class=cFD>NowDateTimeStruct</span><span class=cF0>(&ds);
|
||
|
<a name="l195"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Struct2Date</span><span class=cF0>(&ds)-</span><span class=cFB>local_time_offset</span><span class=cF0>;
|
||
|
<a name="l196"></a>}
|
||
|
</span></pre></body>
|
||
|
</html>
|