Projects acosom ziit ziit-cli Commits fa2a52b4
ctrl k
  • src/interval.c
    ■ ■ ■ ■ ■ ■
    skipped 114 lines
    115 115   
    116 116  static void ziit_get_week(uint64_t *ts, uint64_t *duration)
    117 117  {
    118  - time_t now, start_of_week;
    119  - struct tm *tm_now;
    120  - int seconds_since_monday;
     118 + time_t start_of_week;
     119 + struct tm tm_now, tm_start_of_week;
     120 + int days_since_monday;
    121 121   
    122  - now = time(NULL);
    123  - tm_now = localtime(&now);
     122 + start_of_week = time(NULL);
     123 + localtime_r(&start_of_week, &tm_now);
     124 + days_since_monday = (tm_now.tm_wday + 6) % 7;
    124 125   
    125  - seconds_since_monday = (tm_now->tm_wday + 6) % 7 * 24 * 60 * 60 +
    126  - tm_now->tm_hour * 60 * 60 + tm_now->tm_min * 60 +
    127  - tm_now->tm_sec;
     126 + tm_now.tm_mday -= days_since_monday + 1;
     127 + tm_now.tm_hour = 12;
     128 + tm_now.tm_sec = 0;
     129 + tm_now.tm_min = 0;
    128 130   
    129  - start_of_week = now - seconds_since_monday;
     131 + start_of_week = mktime(&tm_now);
     132 + localtime_r(&start_of_week, &tm_start_of_week);
     133 + 
     134 + tm_start_of_week.tm_hour = 24;
     135 + start_of_week = mktime(&tm_start_of_week);
    130 136   
    131 137   *ts = start_of_week;
    132 138   *duration = 7 * 24 * 60 * 60 - 1;
    skipped 371 lines
  • src/summary.c
    ■ ■ ■ ■ ■ ■
    skipped 81 lines
    82 82  {
    83 83   assert(ptr1 != NULL && ptr2 != NULL);
    84 84   struct tm time_1, time_2;
    85  - time_t t1, t2;
     85 + time_t t1, t2, now;
     86 + 
     87 + now = time(NULL);
     88 + localtime_r(&now, &time_1);
     89 + localtime_r(&now, &time_2);
    86 90   
    87 91   strptime((*ptr1)->name, date_format, &time_1);
    88 92   strptime((*ptr2)->name, date_format, &time_2);
    skipped 11 lines
    100 104   
    101 105  static bool summary_sort_is_alphabetic(const char *date_format)
    102 106  {
    103  - const char *alphabetic_formats[] = {"%m", "%d", ""};
     107 + const char *alphabetic_formats [] = {""};
    104 108   
    105 109   for (int i = 0; i < CAG_ARRAY_SIZE(alphabetic_formats); ++i) {
    106 110   if (strcmp(alphabetic_formats[i], date_format) == 0) {
    skipped 9 lines
    116 120   // Use bubble sort, since it doesn't allocate any memory.
    117 121   // (hopefully there aren't that many intervals.)
    118 122   int (*cmp)(const char *, ZiitSummaryInterval **, ZiitSummaryInterval **);
     123 + ZiitSummaryInterval **il, **ir;
     124 + 
    119 125   if (summary_sort_is_alphabetic(date_format)) {
    120 126   cmp = summary_sort_compare_alphabetic;
    121 127   } else {
    122 128   cmp = summary_sort_compare_date;
    123 129   }
    124  - ZiitSummaryInterval **il, **ir;
     130 + 
    125 131   for (unsigned i = 0; i < response->n_intervals; ++i) {
    126 132   il = response->intervals + i;
    127 133   
    skipped 34 lines
    162 168   printf("%s'%s'\n", from_buffer, sm_interval->name);
    163 169   
    164 170   snprintf(to_buffer, 255, "Entries:");
    165  - pad_right(to_buffer, 255, 10);
     171 + pad_right(to_buffer, 255, 11);
    166 172   printf("%s%li\n", to_buffer, sm_interval->group_entries);
    167 173   
    168 174   snprintf(from_buffer, 255, "TAG");
    skipped 125 lines
Page is in error, reload to recover