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 | |
parent | af0104f64c68a5c5d0b00507494e81d9080b1aa1 (diff) | |
download | gnunet-834c2cf9268d7738b314bfb1e0f11484500d4dbd.tar.gz gnunet-834c2cf9268d7738b314bfb1e0f11484500d4dbd.zip |
-moving time functions from FS to TIME
-rw-r--r-- | src/fs/fs_misc.c | 69 | ||||
-rw-r--r-- | src/fs/gnunet-publish.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_fs_service.h | 27 | ||||
-rw-r--r-- | src/include/gnunet_time_lib.h | 27 | ||||
-rw-r--r-- | src/util/time.c | 70 |
5 files changed, 98 insertions, 97 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 */ |
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index 58beb371c..f960503c2 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -866,7 +866,7 @@ main (int argc, char *const *argv) | |||
866 | GNUNET_GETOPT_OPTION_END | 866 | GNUNET_GETOPT_OPTION_END |
867 | }; | 867 | }; |
868 | bo.expiration_time = | 868 | bo.expiration_time = |
869 | GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); | 869 | GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); |
870 | 870 | ||
871 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 871 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
872 | return 2; | 872 | return 2; |
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 407c5d296..2987302a3 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h | |||
@@ -1630,33 +1630,6 @@ struct GNUNET_FS_BlockOptions | |||
1630 | 1630 | ||
1631 | 1631 | ||
1632 | /** | 1632 | /** |
1633 | * Return the current year (i.e. '2011'). | ||
1634 | */ | ||
1635 | unsigned int | ||
1636 | GNUNET_FS_get_current_year (void); | ||
1637 | |||
1638 | |||
1639 | /** | ||
1640 | * Convert a year to an expiration time of January 1st of that year. | ||
1641 | * | ||
1642 | * @param year a year (after 1970, please ;-)). | ||
1643 | * @return absolute time for January 1st of that year. | ||
1644 | */ | ||
1645 | struct GNUNET_TIME_Absolute | ||
1646 | GNUNET_FS_year_to_time (unsigned int year); | ||
1647 | |||
1648 | |||
1649 | /** | ||
1650 | * Convert an expiration time to the respective year (rounds) | ||
1651 | * | ||
1652 | * @param at absolute time | ||
1653 | * @return year a year (after 1970), 0 on error | ||
1654 | */ | ||
1655 | unsigned int | ||
1656 | GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at); | ||
1657 | |||
1658 | |||
1659 | /** | ||
1660 | * Handle to the file-sharing service. | 1633 | * Handle to the file-sharing service. |
1661 | */ | 1634 | */ |
1662 | struct GNUNET_FS_Handle; | 1635 | struct GNUNET_FS_Handle; |
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index a739d6d7f..3e87309c6 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h | |||
@@ -487,6 +487,33 @@ long long | |||
487 | GNUNET_TIME_get_offset (void); | 487 | GNUNET_TIME_get_offset (void); |
488 | 488 | ||
489 | 489 | ||
490 | /** | ||
491 | * Return the current year (i.e. '2011'). | ||
492 | */ | ||
493 | unsigned int | ||
494 | GNUNET_TIME_get_current_year (void); | ||
495 | |||
496 | |||
497 | /** | ||
498 | * Convert a year to an expiration time of January 1st of that year. | ||
499 | * | ||
500 | * @param year a year (after 1970, please ;-)). | ||
501 | * @return absolute time for January 1st of that year. | ||
502 | */ | ||
503 | struct GNUNET_TIME_Absolute | ||
504 | GNUNET_TIME_year_to_time (unsigned int year); | ||
505 | |||
506 | |||
507 | /** | ||
508 | * Convert an expiration time to the respective year (rounds) | ||
509 | * | ||
510 | * @param at absolute time | ||
511 | * @return year a year (after 1970), 0 on error | ||
512 | */ | ||
513 | unsigned int | ||
514 | GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at); | ||
515 | |||
516 | |||
490 | #if 0 /* keep Emacsens' auto-indent happy */ | 517 | #if 0 /* keep Emacsens' auto-indent happy */ |
491 | { | 518 | { |
492 | #endif | 519 | #endif |
diff --git a/src/util/time.c b/src/util/time.c index 5e9a01b09..fea0947bd 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -559,4 +559,74 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a) | |||
559 | } | 559 | } |
560 | 560 | ||
561 | 561 | ||
562 | /** | ||
563 | * Return the current year (i.e. '2011'). | ||
564 | */ | ||
565 | unsigned int | ||
566 | GNUNET_TIME_get_current_year () | ||
567 | { | ||
568 | time_t tp; | ||
569 | struct tm *t; | ||
570 | |||
571 | tp = time (NULL); | ||
572 | t = gmtime (&tp); | ||
573 | if (t == NULL) | ||
574 | return 0; | ||
575 | return t->tm_year + 1900; | ||
576 | } | ||
577 | |||
578 | |||
579 | /** | ||
580 | * Convert an expiration time to the respective year (rounds) | ||
581 | * | ||
582 | * @param at absolute time | ||
583 | * @return year a year (after 1970), 0 on error | ||
584 | */ | ||
585 | unsigned int | ||
586 | GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at) | ||
587 | { | ||
588 | struct tm *t; | ||
589 | time_t tp; | ||
590 | |||
591 | tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */ | ||
592 | t = gmtime (&tp); | ||
593 | if (t == NULL) | ||
594 | return 0; | ||
595 | return t->tm_year + 1900; | ||
596 | |||
597 | } | ||
598 | |||
599 | |||
600 | /** | ||
601 | * Convert a year to an expiration time of January 1st of that year. | ||
602 | * | ||
603 | * @param year a year (after 1970, please ;-)). | ||
604 | * @return absolute time for January 1st of that year. | ||
605 | */ | ||
606 | struct GNUNET_TIME_Absolute | ||
607 | GNUNET_TIME_year_to_time (unsigned int year) | ||
608 | { | ||
609 | struct GNUNET_TIME_Absolute ret; | ||
610 | time_t tp; | ||
611 | struct tm t; | ||
612 | |||
613 | memset (&t, 0, sizeof (t)); | ||
614 | if (year < 1900) | ||
615 | { | ||
616 | GNUNET_break (0); | ||
617 | return GNUNET_TIME_absolute_get (); /* now */ | ||
618 | } | ||
619 | t.tm_year = year - 1900; | ||
620 | t.tm_mday = 1; | ||
621 | t.tm_mon = 1; | ||
622 | t.tm_wday = 1; | ||
623 | t.tm_yday = 1; | ||
624 | tp = mktime (&t); | ||
625 | GNUNET_break (tp != (time_t) - 1); | ||
626 | ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */ | ||
627 | return ret; | ||
628 | } | ||
629 | |||
630 | |||
631 | |||
562 | /* end of time.c */ | 632 | /* end of time.c */ |