*
* @param date_str input date string.
* @param date time_t to write result to.
+ * @param[in] hint scale for the parsing. Default is "seconds"
* @return
* - 0 on success.
* - -1 on failure.
*/
-int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str)
+int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str, fr_time_res_t hint)
{
int i;
time_t t;
*/
t = strtoul(date_str, &tail, 10);
if (*tail == '\0') {
- *date = fr_unix_time_from_timeval(&(struct timeval) { .tv_sec = t });
+ switch (hint) {
+ case FR_TIME_RES_SEC:
+ t = fr_unix_time_from_sec(t);
+ break;
+
+ case FR_TIME_RES_MSEC:
+ t = fr_unix_time_from_msec(t);
+ break;
+
+ case FR_TIME_RES_USEC:
+ t = fr_unix_time_from_usec(t);
+ break;
+
+ case FR_TIME_RES_NSEC:
+ t = fr_unix_time_from_nsec(t);
+ break;
+
+ default:
+ fr_strerror_printf("Invalid hint %d for time delta", hint);
+ return -1;
+ }
+
+ *date = t;
return 0;
}
ssize_t fr_writev(int fd, struct iovec vector[], int iovcnt, fr_time_delta_t timeout);
ssize_t fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen);
size_t fr_snprint_uint128(char *out, size_t outlen, uint128_t const num);
-int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str);
+int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str, fr_time_res_t hint);
bool fr_multiply(uint64_t *result, uint64_t lhs, uint64_t rhs);
uint64_t fr_multiply_mod(uint64_t lhs, uint64_t rhs, uint64_t mod);
break;
case FR_TIME_RES_MSEC:
- date *= 1000000;
+ fprintf(stderr, "mSEC %lld --> nSEC %lld\n", date, date * (NSEC / MSEC));
+ date *= (NSEC / MSEC);
break;
case FR_TIME_RES_USEC:
- date *= 1000;
+ date *= (NSEC / USEC);
break;
case FR_TIME_RES_NSEC:
case FR_TYPE_DATE:
{
- if (fr_unix_time_from_str(&dst->vb_date, in) < 0) return -1;
+ if (dst_enumv) {
+ if (fr_unix_time_from_str(&dst->vb_date, in, dst_enumv->flags.flag_time_res) < 0) return -1;
+ } else {
+ if (fr_unix_time_from_str(&dst->vb_date, in, FR_TIME_RES_SEC) < 0) return -1;
+ }
dst->enumv = dst_enumv;
}
break;
case FR_TIME_RES_MSEC:
- subseconds /= 1000000;
+ subseconds /= (NSEC / MSEC);
FR_SBUFF_IN_SPRINTF_RETURN(&our_out, ".%03" PRIi64, subseconds);
break;
case FR_TIME_RES_USEC:
- subseconds /= 1000;
+ subseconds /= (NSEC / USEC);
FR_SBUFF_IN_SPRINTF_RETURN(&our_out, ".%06" PRIi64, subseconds);
break;