X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Flib%2Fbtime.c;h=943a8860883b67356e7c00545a855fa840af7c73;hb=3f8a3a045ea058657030f588a10f786449d00e0d;hp=825573e2cf37fd853282ad35d90fd61b4927626f;hpb=23100154053849b142ae88eef37a1c59dd36a52e;p=bacula%2Fbacula diff --git a/bacula/src/lib/btime.c b/bacula/src/lib/btime.c index 825573e2cf..943a886088 100644 --- a/bacula/src/lib/btime.c +++ b/bacula/src/lib/btime.c @@ -4,7 +4,7 @@ * Version $Id$ */ /* - Copyright (C) 2000-2003 Kern Sibbald and John Walker + Copyright (C) 2000-2004 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -28,9 +28,9 @@ * in Bacula (fdate_t, ftime_t, time_t (Unix standard), btime_t, and * utime_t). fdate_t and ftime_t are deprecated and should no longer * be used, and in general, Unix time time_t should no longer be used, - * it is being phased out. - * - * Epoch is the base of Unix time in seconds (time_t, ...) + * it is being phased out. + * + * Epoch is the base of Unix time in seconds (time_t, ...) * and is 1 Jan 1970 at 0:0 UTC * * The major two times that should be left are: @@ -44,21 +44,47 @@ /* Formatted time for user display: dd-Mon-yyyy hh:mm */ char *bstrftime(char *dt, int maxlen, utime_t tim) { - time_t ttime = tim; + time_t ttime = (time_t)tim; struct tm tm; - + /* ***FIXME**** the format and localtime_r() should be user configurable */ localtime_r(&ttime, &tm); strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm); return dt; } +/* Formatted time for user display: dd-Mon-yyyy hh:mm:ss */ +char *bstrftimes(char *dt, int maxlen, utime_t tim) +{ + time_t ttime = (time_t)tim; + struct tm tm; + + /* ***FIXME**** the format and localtime_r() should be user configurable */ + localtime_r(&ttime, &tm); + strftime(dt, maxlen, "%d-%b-%Y %H:%M:%S", &tm); + return dt; +} + + +/* Formatted time for user display: dd-Mon hh:mm */ +char *bstrftime_ny(char *dt, int maxlen, utime_t tim) +{ + time_t ttime = (time_t)tim; + struct tm tm; + + /* ***FIXME**** the format and localtime_r() should be user configurable */ + localtime_r(&ttime, &tm); + strftime(dt, maxlen, "%d-%b %H:%M", &tm); + return dt; +} + + /* Formatted time for user display: dd-Mon-yy hh:mm (no century) */ char *bstrftime_nc(char *dt, int maxlen, utime_t tim) { - time_t ttime = tim; + time_t ttime = (time_t)tim; struct tm tm; - + /* ***FIXME**** the format and localtime_r() should be user configurable */ localtime_r(&ttime, &tm); /* NOTE! since the compiler complains about %y, I use %y and cut the century */ @@ -71,7 +97,7 @@ char *bstrftime_nc(char *dt, int maxlen, utime_t tim) /* Unix time to standard time string yyyy-mm-dd hh:mm:ss */ char *bstrutime(char *dt, int maxlen, utime_t tim) { - time_t ttime = tim; + time_t ttime = (time_t)tim; struct tm tm; localtime_r(&ttime, &tm); strftime(dt, maxlen, "%Y-%m-%d %H:%M:%S", &tm); @@ -79,7 +105,7 @@ char *bstrutime(char *dt, int maxlen, utime_t tim) } /* Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time */ -utime_t str_to_utime(char *str) +utime_t str_to_utime(char *str) { struct tm tm; time_t ttime; @@ -90,7 +116,7 @@ utime_t str_to_utime(char *str) } if (tm.tm_mon > 0) { tm.tm_mon--; - } else { + } else { return 0; } if (tm.tm_year >= 1900) { @@ -101,7 +127,7 @@ utime_t str_to_utime(char *str) tm.tm_wday = tm.tm_yday = 0; tm.tm_isdst = -1; ttime = mktime(&tm); - if (ttime == -1) { + if (ttime == -1) { ttime = 0; } return (utime_t)ttime; @@ -126,7 +152,7 @@ btime_t get_current_btime() /* Convert btime to Unix time */ time_t btime_to_unix(btime_t bt) { - return (time_t)(bt/1000000); + return (time_t)(bt/1000000); } /* Convert btime to utime */ @@ -136,7 +162,7 @@ utime_t btime_to_utime(btime_t bt) } /* - * Return the week of the month, base 0 (wpos) + * Return the week of the month, base 0 (wom) * given tm_mday and tm_wday. Value returned * can be from 0 to 4 => week1, ... week5 */ @@ -148,13 +174,13 @@ int tm_wom(int mday, int wday) fs += 7; } if (mday <= fs) { -// Dmsg2(100, "wom=0 wday=%d <= fs=%d\n", wday, fs); +// Dmsg3(100, "mday=%d wom=0 wday=%d <= fs=%d\n", mday, wday, fs); return 0; } int wom = 1 + (mday - fs - 1) / 7; -// Dmsg3(100, "wom=%d wday=%d fs=%d\n", wom, wday, fs); +// Dmsg4(100, "mday=%d wom=%d wday=%d fs=%d\n", mday, wom, wday, fs); return wom; -} +} /* * Given a Unix date return the week of the year. @@ -311,7 +337,7 @@ void time_decode(ftime_t time, uint8_t *hour, uint8_t *minute, *minute = (uint8_t) ((ij / 60L) % 60L); *second = (uint8_t) (ij % 60L); if (second_fraction != NULL) { - *second_fraction = time - floor(time); + *second_fraction = (float32_t)(time - floor(time)); } } @@ -328,13 +354,13 @@ void date_time_decode(struct date_time *dt, time_decode(dt->julian_day_fraction, hour, minute, second, second_fraction); } -/* tm_encode -- Encode a civil date and time from a tm structure +/* tm_encode -- Encode a civil date and time from a tm structure * to a Julian day and day fraction. */ /* Deprecated. Do not use. */ void tm_encode(struct date_time *dt, - struct tm *tm) + struct tm *tm) { uint32_t year; uint8_t month, day, hour, minute, second; @@ -355,7 +381,7 @@ void tm_encode(struct date_time *dt, /* Deprecated. Do not use. */ void tm_decode(struct date_time *dt, - struct tm *tm) + struct tm *tm) { uint32_t year; uint8_t month, day, hour, minute, second;