1 //metadoc Date copyright Steve Dekorte 2002
2 //metadoc Date license BSD revised
3 
4 #include "Base.h"
5 
6 #ifndef DATE_DEFINED
7 #define DATE_DEFINED 1
8 
9 #include "Common.h"
10 #include "Duration.h"
11 #include "PortableGettimeofday.h"
12 #include <time.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 typedef struct
19 {
20 	struct timeval  tv;
21 	struct timezone tz;
22 } Date;
23 
24 BASEKIT_API double Date_SecondsFrom1970ToNow(void);
25 
26 BASEKIT_API Date *Date_new(void);
27 BASEKIT_API void Date_copy_(Date *self, const Date *other);
28 BASEKIT_API void Date_free(Date *self);
29 BASEKIT_API int Date_compare(const Date *self, const Date *other);
30 
31 BASEKIT_API void Date_now(Date *self);
32 BASEKIT_API void Date_setToLocalTimeZone(Date *self);
33 BASEKIT_API double Date_Clock(void);
34 
35 BASEKIT_API void Date_fromLocalTime_(Date *self, struct tm *t);
36 BASEKIT_API void Date_fromTime_(Date *self, time_t t);
37 BASEKIT_API time_t Date_asTime(const Date *self);
38 
39 // zone
40 
41 BASEKIT_API void Date_setToLocalTimeZone(Date *self);
42 BASEKIT_API struct timezone Date_timeZone(const Date *self);
43 BASEKIT_API void Date_setTimeZone_(Date *self, struct timezone tz);
44 BASEKIT_API void Date_convertToTimeZone_(Date *self, struct timezone tz);
45 
46 // components
47 
48 BASEKIT_API void Date_setYear_(Date *self, long y);
49 BASEKIT_API long Date_year(const Date *self);
50 
51 BASEKIT_API void Date_setMonth_(Date *self, int m);
52 BASEKIT_API int Date_month(const Date *self);
53 
54 BASEKIT_API void Date_setDay_(Date *self, int d);
55 BASEKIT_API int Date_day(const Date *self);
56 
57 BASEKIT_API void Date_setHour_(Date *self, int h);
58 BASEKIT_API int Date_hour(const Date *self);
59 
60 BASEKIT_API void Date_setMinute_(Date *self, int m);
61 BASEKIT_API int Date_minute(const Date *self);
62 
63 BASEKIT_API void Date_setSecond_(Date *self, double s);
64 BASEKIT_API double Date_second(const Date *self);
65 
66 BASEKIT_API UArray *Date_asSerialization(Date *self);
67 BASEKIT_API Date *Date_fromSerialization(Date *self, UArray *serialization);
68 
69 BASEKIT_API unsigned char Date_isDaylightSavingsTime(const Date *self);
70 BASEKIT_API int Date_isLeapYear(const Date *self);
71 
72 // seconds
73 
74 BASEKIT_API double Date_asSeconds(const Date *self);
75 BASEKIT_API void Date_fromSeconds_(Date *self, double s);
76 
77 BASEKIT_API void Date_addSeconds_(Date *self, double s);
78 BASEKIT_API double Date_secondsSince_(const Date *self, const Date *other);
79 
80 // format
81 
82 BASEKIT_API void Date_fromString_format_(Date *self, const char *s, const char *format);
83 
84 // durations
85 
86 BASEKIT_API Duration *Date_newDurationBySubtractingDate_(const Date *self, const Date *other);
87 BASEKIT_API void Date_addDuration_(Date *self, const Duration *d);
88 BASEKIT_API void Date_subtractDuration_(Date *self, const Duration *d);
89 
90 BASEKIT_API double Date_secondsSinceNow(const Date *self);
91 
92 BASEKIT_API UArray *Date_asString(const Date *self, const char *format);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 #endif
98