]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
log: fix lxc_unix_epoch_to_utc() 1447/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 27 Feb 2017 15:02:24 +0000 (16:02 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 27 Feb 2017 15:02:24 +0000 (16:02 +0100)
The conversion algorithm used uses a clever trick by letting a year start at 1
March. So we need to add 1 for January and February.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/log.c

index cdeec9f393630d09d5047b1f289dfe4484bac546..339b81c61cf6e31ce7cc3e71119ac69ab3fbc09f 100644 (file)
@@ -173,7 +173,7 @@ int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time
        yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
 
        /* Given year-of-era, and era, one can now compute the year. */
-       year = (yoe) + era * 400;
+       year = yoe + era * 400;
 
        /* Also the day-of-year, again with the year beginning on Mar. 1, can be
         * computed from the day-of-era and year-of-era.
@@ -193,6 +193,11 @@ int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time
         */
        month = mp + (mp < 10 ? 3 : -9);
 
+       /* The algorithm assumes that a year begins on 1 March, so add 1 before
+        * that. */
+       if (month < 3)
+               year++;
+
        /* Transform days in the epoch to seconds. */
        d_in_s = epoch_to_days * 86400;