* Relative time update (eg "2 days ago"). If we haven't set the time * yet, we need to set it from current time. * * The tm->tm_mday field has an additional logic of using negative values * for date adjustments: -2 means yesterday and -3 the day before that, * and so on. The idea is to defer such adjustments until we are sure * there's no explicit mday specification in the approxidate stri
| 1078 | * there's no explicit mday specification in the approxidate string. |
| 1079 | */ |
| 1080 | static time_t update_tm(struct tm *tm, struct tm *now, time_t sec) |
| 1081 | { |
| 1082 | time_t n; |
| 1083 | |
| 1084 | if (tm->tm_mday < 0) { |
| 1085 | int offset = tm->tm_mday + 1; |
| 1086 | if (sec == 0 && offset < 0) |
| 1087 | sec = -offset * 24*60*60; |
| 1088 | tm->tm_mday = now->tm_mday; |
| 1089 | } |
| 1090 | if (tm->tm_mon < 0) |
| 1091 | tm->tm_mon = now->tm_mon; |
| 1092 | if (tm->tm_year < 0) { |
| 1093 | tm->tm_year = now->tm_year; |
| 1094 | if (tm->tm_mon > now->tm_mon) |
| 1095 | tm->tm_year--; |
| 1096 | } |
| 1097 | |
| 1098 | n = mktime(tm) - sec; |
| 1099 | localtime_r(&n, tm); |
| 1100 | return n; |
| 1101 | } |
| 1102 | |
| 1103 | /* |
| 1104 | * Do we have a pending number at the end, or when |
no test coverage detected