diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-08 18:07:21 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-08 18:07:21 +0000 |
commit | 834c2cf9268d7738b314bfb1e0f11484500d4dbd (patch) | |
tree | f8b190e7f7a3af4266f9c2437caf74bae5a5293f /src/fs/fs_misc.c | |
parent | af0104f64c68a5c5d0b00507494e81d9080b1aa1 (diff) | |
download | gnunet-834c2cf9268d7738b314bfb1e0f11484500d4dbd.tar.gz gnunet-834c2cf9268d7738b314bfb1e0f11484500d4dbd.zip |
-moving time functions from FS to TIME
Diffstat (limited to 'src/fs/fs_misc.c')
-rw-r--r-- | src/fs/fs_misc.c | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c index ee24fa250..bca16e545 100644 --- a/src/fs/fs_misc.c +++ b/src/fs/fs_misc.c | |||
@@ -159,73 +159,4 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData | |||
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | /** | ||
163 | * Return the current year (i.e. '2011'). | ||
164 | */ | ||
165 | unsigned int | ||
166 | GNUNET_FS_get_current_year () | ||
167 | { | ||
168 | time_t tp; | ||
169 | struct tm *t; | ||
170 | |||
171 | tp = time (NULL); | ||
172 | t = gmtime (&tp); | ||
173 | if (t == NULL) | ||
174 | return 0; | ||
175 | return t->tm_year + 1900; | ||
176 | } | ||
177 | |||
178 | |||
179 | /** | ||
180 | * Convert a year to an expiration time of January 1st of that year. | ||
181 | * | ||
182 | * @param year a year (after 1970, please ;-)). | ||
183 | * @return absolute time for January 1st of that year. | ||
184 | */ | ||
185 | struct GNUNET_TIME_Absolute | ||
186 | GNUNET_FS_year_to_time (unsigned int year) | ||
187 | { | ||
188 | struct GNUNET_TIME_Absolute ret; | ||
189 | time_t tp; | ||
190 | struct tm t; | ||
191 | |||
192 | memset (&t, 0, sizeof (t)); | ||
193 | if (year < 1900) | ||
194 | { | ||
195 | GNUNET_break (0); | ||
196 | return GNUNET_TIME_absolute_get (); /* now */ | ||
197 | } | ||
198 | t.tm_year = year - 1900; | ||
199 | t.tm_mday = 1; | ||
200 | t.tm_mon = 1; | ||
201 | t.tm_wday = 1; | ||
202 | t.tm_yday = 1; | ||
203 | tp = mktime (&t); | ||
204 | GNUNET_break (tp != (time_t) - 1); | ||
205 | ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */ | ||
206 | return ret; | ||
207 | } | ||
208 | |||
209 | |||
210 | /** | ||
211 | * Convert an expiration time to the respective year (rounds) | ||
212 | * | ||
213 | * @param at absolute time | ||
214 | * @return year a year (after 1970), 0 on error | ||
215 | */ | ||
216 | unsigned int | ||
217 | GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at) | ||
218 | { | ||
219 | struct tm *t; | ||
220 | time_t tp; | ||
221 | |||
222 | tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */ | ||
223 | t = gmtime (&tp); | ||
224 | if (t == NULL) | ||
225 | return 0; | ||
226 | return t->tm_year + 1900; | ||
227 | |||
228 | } | ||
229 | |||
230 | |||
231 | /* end of fs_misc.c */ | 162 | /* end of fs_misc.c */ |