-
Notifications
You must be signed in to change notification settings - Fork 0
/
Date.c
executable file
·83 lines (70 loc) · 1.84 KB
/
Date.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Date.c
// CIS 308 Project Final
//
// Created by Weston Chan, Cale Povilonis, Damon Jones.
//
#include "Date.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char months1[12][10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
Date * new_date(Event * event[3][24], int day, Month month, int year) {
if (event == NULL || (day < 0 || day > 31) || year < 0) { return NULL;}
Date * d = malloc(sizeof(Date));
d->event[0][0] = event[0][0];
d->month = month;
d->day = day;
d->year = year;
return d;
}
Date * addEvent(Date * day, Event * e) {
if(day == NULL || e == NULL) return NULL;
if(e->start < 0 || e->end > 24) return NULL;
int time = e->start;
while(time < e->end){
day->event[e -> type][time] = e;
time++;
}
}
char * toDateString(Date * day, char * str) {
if(day == NULL || str == NULL) return "";
str[0] = '\0';
char title[TITLELENGTH];
strcat(str, " \t");
for(int i = 0; i < 3; i++) {
//printTypes();
strcpy(title, returnTypes(i));
while(strlen(title) != TITLELENGTH - 1) {
strcat(title, " ");
}
strcat(str, title);
strcat(str, "\t");
}
strcat(str, "\n\n");
char tempstr[2];
for(int i = 0; i < 24; i++) {
if(i <= 9)strcat(str, "0");
sprintf(tempstr, "%d", i);
strcat(str, tempstr);
strcat(str, ":00\t");
for(int j = 0; j < 3; j++) {
if(day->event[j][i] == NULL)
for(int k = 0; k < TITLELENGTH-1; k++)
strcat(str, " ");
else {
strcpy(title, day -> event[j][i] ->title);
while(strlen(title) != TITLELENGTH - 1) {
strcat(title, " ");
}
strcat(str, title);
}
strcat(str, "\t");
}
strcat(str, "\n");
}
return str;
}
int dateEquals(Date * day1, int day, int month, int year) {
if( day1->year == year && day1->month == month && day1->day == day) return 0; return 1;
}