LTCD_070816.ISO
This commit is contained in:
1 parent
d14bbc24f9
commit
0e9364ff4c
506 files changed
+157705
-41812
No files matched your search
@@ -0,0 +1,217 @@
|
||||
U2 month_start_days1[12]={
|
||||
0,31,59,90,120,151,181,212,243,273,304,334};
|
||||
U2 month_start_days2[12]={
|
||||
0,31,60,91,121,152,182,213,244,274,305,335};
|
||||
|
||||
I8 YearStartDate(I8 year)
|
||||
{
|
||||
I8 y1=year-1;
|
||||
I8 yd4000=y1/4000,yd400=y1/400,yd100=y1/100,yd4=y1/4;
|
||||
return year*365+yd4-yd100+yd400-yd4000;
|
||||
}
|
||||
|
||||
LTDate ToLTDate(LTDateStruct *d)
|
||||
{
|
||||
LTDate ltdt;
|
||||
I8 i1,i2;
|
||||
i1=YearStartDate(d->year);
|
||||
i2=YearStartDate(d->year+1);
|
||||
if (i2-i1==365)
|
||||
i1+=month_start_days1[d->month-1];
|
||||
else
|
||||
i1+=month_start_days2[d->month-1];
|
||||
ltdt.date=i1+d->day_of_month-1;
|
||||
ltdt.time=(d->ten_thousandths+10000*(d->seconds+60*(d->minutes+60*(d->hours))))<<21/(15*15*3*625);
|
||||
return ltdt;
|
||||
}
|
||||
|
||||
I8 DayOfWeek(I8 i)
|
||||
{
|
||||
i+=LT_BASE_DAY_OF_WEEK;
|
||||
if (i>=0)
|
||||
return i % 7;
|
||||
else
|
||||
return 6-(6-i)%7;
|
||||
}
|
||||
|
||||
void ToLTDateStruct(LTDateStruct *d,LTDate ltdt)
|
||||
{
|
||||
I8 i,date=ltdt.date;
|
||||
U8 k;
|
||||
d->day_of_week=DayOfWeek(date);
|
||||
d->year=(date+1)*100000/36524225;
|
||||
i=YearStartDate(d->year);
|
||||
date-=i;
|
||||
if (YearStartDate(d->year+1)-i==365) {
|
||||
k=0;
|
||||
while (date>=month_start_days1[k+1] && k<11)
|
||||
k++;
|
||||
date-=month_start_days1[k];
|
||||
} else {
|
||||
k=0;
|
||||
while (date>=month_start_days2[k+1] && k<11)
|
||||
k++;
|
||||
date-=month_start_days2[k];
|
||||
}
|
||||
d->month=k+1;
|
||||
d->day_of_month=date+1;
|
||||
k=(625*15*15*3*ltdt.time)>>21+1;
|
||||
d->ten_thousandths=k%10000; k/=100;
|
||||
d->hundredths=k%100; k/=100;
|
||||
d->seconds=k%60;k/=60;
|
||||
d->minutes=k%60;
|
||||
d->hours =k/60;
|
||||
}
|
||||
|
||||
I8 FirstDayOfMonth(I8 i)
|
||||
{
|
||||
LTDateStruct d;
|
||||
LTDate ltdt=0;
|
||||
ltdt.date=i;
|
||||
ToLTDateStruct(&d,ltdt);
|
||||
d.day_of_month=1;
|
||||
ltdt=ToLTDate(&d);
|
||||
return ltdt.date;
|
||||
}
|
||||
|
||||
I8 LastDayOfMonth(I8 i)
|
||||
{
|
||||
LTDateStruct d;
|
||||
LTDate ltdt=0;
|
||||
ltdt.date=i;
|
||||
ToLTDateStruct(&d,ltdt);
|
||||
d.month++;
|
||||
if (d.month==13) {
|
||||
d.month=0;
|
||||
d.year++;
|
||||
}
|
||||
d.day_of_month=1;
|
||||
ltdt=ToLTDate(&d);
|
||||
return ltdt.date-1;
|
||||
}
|
||||
|
||||
I8 FirstDayOfYear(I8 i)
|
||||
{
|
||||
LTDateStruct d;
|
||||
LTDate ltdt=0;
|
||||
ltdt.date=i;
|
||||
ToLTDateStruct(&d,ltdt);
|
||||
d.day_of_month=1;
|
||||
d.month=1;
|
||||
ltdt=ToLTDate(&d);
|
||||
return ltdt.date;
|
||||
}
|
||||
|
||||
I8 LastDayOfYear(I8 i)
|
||||
{
|
||||
LTDateStruct d;
|
||||
LTDate ltdt=0;
|
||||
ltdt.date=i;
|
||||
ToLTDateStruct(&d,ltdt);
|
||||
d.day_of_month=1;
|
||||
d.month=1;
|
||||
d.year++;
|
||||
ltdt=ToLTDate(&d);
|
||||
return ltdt.date-1;
|
||||
}
|
||||
|
||||
|
||||
U8 Bcd2Bin(U8 b)
|
||||
{
|
||||
U8 i,result=0;
|
||||
for (i=0;i<16;i++) {
|
||||
result=result*10+b>>60;
|
||||
b<<=4;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void GetCurTimeLTDateStruct(LTDateStruct *r)
|
||||
{
|
||||
U8 i;
|
||||
U8 old_flags=GetFlags;
|
||||
U1 *p=r;
|
||||
BoolU4 is_bcd;
|
||||
|
||||
MemSet(r,0,sizeof(LTDateStruct));
|
||||
Cli;
|
||||
if (mp_cnt>1)
|
||||
while (LBts(&sys_semas[SYS_SEMA_SYS_DATE],0));
|
||||
do OutP(0x70,0x0A);
|
||||
while (InP(0x71) & 0x80);
|
||||
|
||||
OutP(0x70,0);
|
||||
p[3]=InP(0x71);
|
||||
OutP(0x70,2);
|
||||
p[4]=InP(0x71);
|
||||
OutP(0x70,4);
|
||||
p[5]=InP(0x71);
|
||||
|
||||
OutP(0x70,6);
|
||||
p[6]=InP(0x71);
|
||||
OutP(0x70,7);
|
||||
p[7]=InP(0x71);
|
||||
OutP(0x70,8);
|
||||
p[8]=InP(0x71);
|
||||
OutP(0x70,9);
|
||||
p[9]=InP(0x71);
|
||||
|
||||
OutP(0x70,0x0B);
|
||||
if (InP(0x71) & 4)
|
||||
is_bcd=FALSE;
|
||||
else
|
||||
is_bcd=TRUE;
|
||||
|
||||
LBtr(&sys_semas[SYS_SEMA_SYS_DATE],0);
|
||||
SetFlags(old_flags);
|
||||
if (is_bcd) {
|
||||
for (i=3;i<10;i++)
|
||||
p[i]=Bcd2Bin(p[i]);
|
||||
}
|
||||
if (r->year>255) r->year=255;
|
||||
r->year+=2000;
|
||||
if (r->month>12) r->month=12;
|
||||
if (r->day_of_month>31) r->day_of_month=31;
|
||||
if (r->day_of_week>6) r->day_of_week=6;
|
||||
if (r->hours>23) r->hours=23;
|
||||
if (r->minutes>59) r->minutes=59;
|
||||
if (r->seconds>59) r->seconds=59;
|
||||
if (r->hundredths>99) r->hundredths=99;
|
||||
}
|
||||
|
||||
LTDate GetCurTimeLTDate()
|
||||
{
|
||||
LTDate result;
|
||||
LTDateStruct r;
|
||||
GetCurTimeLTDateStruct(&r);
|
||||
result=ToLTDate(&r)-local_time_offset;
|
||||
return result;
|
||||
}
|
||||
|
||||
void LTDateToISO(ISODate *dst,LTDate ltdate)
|
||||
{
|
||||
LTDateStruct d;
|
||||
ToLTDateStruct(&d,ltdate);
|
||||
dst->year=d.year-ISO_BASE_YEAR;
|
||||
dst->mon=d.month;
|
||||
dst->day=d.day_of_month;
|
||||
dst->hour=d.hours;
|
||||
dst->min=d.minutes;
|
||||
dst->sec=d.seconds;
|
||||
dst->hund=d.hundredths;
|
||||
}
|
||||
|
||||
LTDate ISOToLTDate(ISODate *dt)
|
||||
{
|
||||
LTDateStruct ltdt;
|
||||
ltdt.day_of_month=dt->day;
|
||||
ltdt.month=dt->mon;
|
||||
ltdt.year=dt->year+ISO_BASE_YEAR;
|
||||
ltdt.ten_thousandths=dt->hund*100;
|
||||
ltdt.hundredths=dt->hund;
|
||||
ltdt.seconds=dt->sec;
|
||||
ltdt.minutes=dt->min;
|
||||
ltdt.hours=dt->hour;
|
||||
return ToLTDate(<dt);
|
||||
}
|
||||
Reference in new issue
Block a user