OSDN Git Service

addid library source 20140221
[zither/ds-zither.git] / sources / lib / libms / day_plasminus.c
1
2
3
4 int isleap(int year)
5 {
6 return (year % 4 == 0 && year % 100 != 0 || year % 400);
7
8
9
10 // 翌日の日月年を出す関数
11 int day_plasminus(int * y, int * m, int * d, char mark)
12 {
13
14 int day[2][13] = {
15 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
16 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }};
17
18
19 if(mark == '-'){
20    if(*d != 1){
21       (*d)--;
22       } 
23    else{
24       if(*m != 1){
25          (*m)--;
26          }
27       else {
28          (*y)--;
29          *m = 12;
30          }
31       *d = day[isleap(*y)][*m];
32       }
33    } 
34
35 else if(mark == '+'){
36    if (*d != day[isleap(*y)][*m]) {
37       (*d)++;
38       }
39    else {
40       if (*m != 12) {
41          (*m)++;
42          }
43       else {
44          (*y)++;
45          *m = 1;
46          }
47       *d = 1;
48       }
49    }
50
51 return 0;
52 }
53
54
55