Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const unsigned char shmtable[6][12]={
{11,10,10,9,9,9,8,9,9,10,11,9},
{20,20,21,21,22,22,22,22,21,21,20,19},
{11,10,10,9,9,9,8,9,9,10,11,10},
{20,20,21,21,22,22,22,22,21,21,20,19},
{12,11,11,10,10,10,9,10,10,11,12,10},
{19,19,20,20,21,21,21,21,20,20,19,18}};
const unsigned char miltable[6][12]={
{20,19,19,19,20,20,21,21,21,21,20,20},
{10,11,10,12,11,11,10,10,10,9,10,10},
{19,18,20,20,21,21,22,22,22,22,21,21},
{11,12,10,11,10,10,9,9,9,8,9,9},
{20,19,20,20,21,21,22,22,22,22,21,21},
{10,11,9,11,10,10,9,9,9,8,9,9}};
struct date{
unsigned char day;
unsigned char month;
unsigned char year;
};
struct date shmdate,mildate ;
/************************************************** ***********************/
void miltoshmcv(unsigned char ym,unsigned char mm,unsigned char dm)
{
unsigned char k,t1,t2;
k=ym%4;
if(k==3)
k=2;
k*=2;
t1=miltable[k][mm-1];
t2=miltable[k+1][mm-1];
if(mm<3 || (mm==3 && dm<=miltable[k][mm-1]))
shmdate.year = ym + 78;
else
shmdate.year = ym + 79;
if(dm<=t1)
{
shmdate.day=dm+t2;
shmdate.month=(mm+8)%12+1;
}
else
{
shmdate.day=dm-t1;
shmdate.month=(mm+9)%12+1;
}
}
/************************************************** ********************/
void shmtomilcv(unsigned char ys ,unsigned char ms,unsigned char ds)
{
unsigned char k,t1,t2;
k = yss%4;
if( k == 0)
k = 2;
else
k = k + k;
t1 =shmtable[k - 2][ms-1];
t2 = shmtable[k-1][ms-1];
if(ms<10 || (ms==10 && ds <= shmtable[k-2][ms-1]))
mildate.year = ys - 79;
else
mildate.year = ys - 78;
if(ds <= t1)
{
mildate.day = ds + t2;
mildate.month = (ms + 1)%12 + 1;
}
else
{
mildate.day= ds - t1;
mildate.month= (ms + 2)%12 + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment