THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

74 lines
1.5 KiB

  1. #include "cache.h"
  2. static const char *usage_msg = "\n"
  3. " test-date show [time_t]...\n"
  4. " test-date parse [date]...\n"
  5. " test-date approxidate [date]...\n";
  6. static void show_dates(char **argv, struct timeval *now)
  7. {
  8. struct strbuf buf = STRBUF_INIT;
  9. for (; *argv; argv++) {
  10. time_t t = atoi(*argv);
  11. show_date_relative(t, 0, now, &buf);
  12. printf("%s -> %s\n", *argv, buf.buf);
  13. }
  14. strbuf_release(&buf);
  15. }
  16. static void parse_dates(char **argv, struct timeval *now)
  17. {
  18. struct strbuf result = STRBUF_INIT;
  19. for (; *argv; argv++) {
  20. unsigned long t;
  21. int tz;
  22. strbuf_reset(&result);
  23. parse_date(*argv, &result);
  24. if (sscanf(result.buf, "%lu %d", &t, &tz) == 2)
  25. printf("%s -> %s\n",
  26. *argv, show_date(t, tz, DATE_MODE(ISO8601)));
  27. else
  28. printf("%s -> bad\n", *argv);
  29. }
  30. strbuf_release(&result);
  31. }
  32. static void parse_approxidate(char **argv, struct timeval *now)
  33. {
  34. for (; *argv; argv++) {
  35. time_t t;
  36. t = approxidate_relative(*argv, now);
  37. printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601)));
  38. }
  39. }
  40. int main(int argc, char **argv)
  41. {
  42. struct timeval now;
  43. const char *x;
  44. x = getenv("TEST_DATE_NOW");
  45. if (x) {
  46. now.tv_sec = atoi(x);
  47. now.tv_usec = 0;
  48. }
  49. else
  50. gettimeofday(&now, NULL);
  51. argv++;
  52. if (!*argv)
  53. usage(usage_msg);
  54. if (!strcmp(*argv, "show"))
  55. show_dates(argv+1, &now);
  56. else if (!strcmp(*argv, "parse"))
  57. parse_dates(argv+1, &now);
  58. else if (!strcmp(*argv, "approxidate"))
  59. parse_approxidate(argv+1, &now);
  60. else
  61. usage(usage_msg);
  62. return 0;
  63. }