Please look at below code. I have tried for year but I have no
idea how I go for rest(month,days,hour,minutes and second).
Code:
typedef struct{
unsigned int date : 5;
unsigned int month : 4;
unsigned int year : 14;
unsigned int hours : 5;
unsigned int minutes : 6;
unsigned int seconds : 6;
} DL_DATE;
//Converts the date in the d1 to string if fails returns 0
int Dldate2Str(DL_DATE * d1,char *date);
//Extract Date from date to d1 if fails returns 0
int ParseDate(char * date,DL_DATE * d1)
int DlDaysInMonth(char * date){
int days[]={31,0,31,30,31,30,31,31,30,31,30,31};
days[1]=((DlYear(date)%4==0 && DlYear(date)%100 !=0) || DlYear(date)%400==0)?29:28;
return days[DlMonth(date)-1];
}
int DlDaysInYear(char * date){
return ((DlYear(date)%4==0 && DlYear(date)%100 !=0) || DlYear(date)%400==0)?366:365;
}
int DlDateAdd(char ch,int num,char * date){
/* y -years
* m -months
* d -days
* h -hours
* n -minutes
* s -seconds
*/
DL_DATE d1;
char tempdate[20];
if(ParseDate(date,&d1)){
ch=tolower(ch);
switch(ch){
case 'y':
d1.year += num;
if ((int)d1.year < 0 || (int)d1.year > 9999 )
return 0;
Dldate2Str(&d1,date);
break;
case 'm':
break;
case 'd':
break;
case 'h':
break;
case 'n':
break;
case 's':
break;
default:
break;
}
}else{
return 0;
}
return 1;
}