1 /*
2 Copyright (C) 2015-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5
6 /*
7 WARNING: This file was generated by the dkct program (see
8 http://dktools.sourceforge.net/ for details).
9 Changes you make here will be lost if dkct is run again!
10 You should modify the original source and run dkct on it.
11 Original source: dk4ctime.ctr
12 */
13
14 /** @file dk4ctime.c The dk4ctime module.
15 */
16
17
18 #include "dk4conf.h"
19
20 #if DK4_HAVE_ASSERT_H
21 #ifndef ASSERT_H_INCLUDED
22 #include <assert.h>
23 #define ASSERT_H_INCLUDED 1
24 #endif
25 #endif
26
27 #include <libdk4base/dk4types.h>
28
29 #include <libdk4c/dk4ctime.h>
30
31 #ifndef DK4REC22_H_INCLUDED
32 #include <libdk4c/dk4rec22.h>
33 #endif
34
35 #ifndef DK4TIME_H_INCLUDED
36 #include <libdk4c/dk4time.h>
37 #endif
38
39 #ifndef DK4TIMEDK_H_INCLUDED
40 #include <libdk4c/dk4timedk.h>
41 #endif
42
43 #ifndef DK4TIME08_H_INCLUDED
44 #include <libdk4c/dk4time08.h>
45 #endif
46
47
48
49 int
50
dk4clocktime_get(dk4_clock_time_t * dptr)51 dk4clocktime_get(dk4_clock_time_t *dptr)
52 {
53 #if DK4_USE_ASSERT
54 assert(NULL != dptr);
55 #endif
56 if (NULL != dptr) {
57 #if DK4_ON_WINDOWS && (DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT)
58 GetLocalTime(dptr);
59 return 1;
60 #else
61 dk4time_get(dptr);
62 return 1;
63 #endif
64 } else {
65 return 0;
66 }
67 }
68
69
70
71 int
dk4clocktime_compare(const dk4_clock_time_t * l,const dk4_clock_time_t * r)72 dk4clocktime_compare(const dk4_clock_time_t *l, const dk4_clock_time_t *r)
73 {
74 int back = 0;
75 if (NULL != l) {
76 if (NULL != r) {
77 #if DK4_ON_WINDOWS && (DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT)
78 if (l->wYear > r->wYear) {
79 back = 1;
80 } else {
81 if (l->wYear < r->wYear) {
82 back = -1;
83 }
84 }
85 if (0 == back) {
86 if (l->wMonth > r->wMonth) {
87 back = 1;
88 } else {
89 if (l->wMonth < r->wMonth) {
90 back = -1;
91 }
92 }
93 }
94 if (0 == back) {
95 if (l->wDay > r->wDay) {
96 back = 1;
97 } else {
98 if (l->wDay < r->wDay) {
99 back = -1;
100 }
101 }
102 }
103 if (0 == back) {
104 if (l->wHour > r->wHour) {
105 back = 1;
106 } else {
107 if (l->wHour < r->wHour) {
108 back = -1;
109 }
110 }
111 }
112 if (0 == back) {
113 if (l->wMinute > r->wMinute) {
114 back = 1;
115 } else {
116 if (l->wMinute < r->wMinute) {
117 back = -1;
118 }
119 }
120 }
121 if (0 == back) {
122 if (l->wSecond > r->wSecond) {
123 back = 1;
124 } else {
125 if (l->wSecond < r->wSecond) {
126 back = -1;
127 }
128 }
129 }
130 #else
131 if (*l > *r) {
132 back = 1;
133 } else {
134 if (*l < *r) {
135 back = -1;
136 }
137 }
138 #endif
139 } else {
140 back = 1;
141 }
142 } else {
143 if (NULL != r) {
144 back = -1;
145 }
146 }
147 return back;
148 }
149
150
151
152 /** Convert timestamp to text ``yyyy-mm-dd hh:mm:ss''.
153 @param dptr Result buffer address.
154 @param dsz Result buffer size (number of dkChar).
155 @param clt Timestamp to convert.
156 @param erp Error report, may be NULL.
157 @return 1 on success, 0 on error.
158 */
159 int
dk4clocktime_to_text(dkChar * dptr,size_t dsz,const dk4_clock_time_t * clt,dk4_er_t * erp)160 dk4clocktime_to_text(
161 dkChar *dptr,
162 size_t dsz,
163 const dk4_clock_time_t *clt,
164 dk4_er_t *erp
165 )
166 {
167 #if DK4_ON_WINDOWS && (DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT)
168 #if DK4_USE_ASSERT
169 assert(NULL != dptr);
170 assert(0 < dsz);
171 assert(NULL != clt);
172 #endif
173 back = dk4time_to_text(
174 dptr, dsz, DK4_TIMEFORMAT_DATE_TIME,
175 clt->wYear, clt->wMonth, clt->wDay, clt->wHour, clt->wMinute, clt->wSecond,
176 erp
177 );
178 #else
179 #if DK4_CHAR_SIZE > 1
180 char buf[32];
181 int back = 0;
182 #if DK4_USE_ASSERT
183 assert(NULL != dptr);
184 assert(0 < dsz);
185 assert(NULL != clt);
186 #endif
187 if (0 != dk4time_as_text_c8(buf, sizeof(buf), clt, erp)) {
188 back = dk4recode_char_to_dk(dptr, dsz, buf, erp);
189 }
190 return back;
191 #else
192 return (dk4time_as_text(dptr, dsz, clt, erp));
193 #endif
194 #endif
195 }
196
197