aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/bfc/util/timefmt.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/bfc/util/timefmt.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/Wasabi/bfc/util/timefmt.cpp')
-rw-r--r--Src/Wasabi/bfc/util/timefmt.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/Src/Wasabi/bfc/util/timefmt.cpp b/Src/Wasabi/bfc/util/timefmt.cpp
new file mode 100644
index 00000000..f0968ac6
--- /dev/null
+++ b/Src/Wasabi/bfc/util/timefmt.cpp
@@ -0,0 +1,71 @@
+#include <precomp.h>
+#include <bfc/wasabi_std.h>
+#include <time.h>
+#include "timefmt.h"
+
+void TimeFmt::printMinSec(int sec, wchar_t *buf, int buflen)
+{
+ int minutes, seconds;
+ int negative = sec < 0;
+
+ if (buf == NULL) return;
+
+ if (sec == -1)
+ {
+ *buf = 0;
+ return;
+ }
+
+ seconds = sec % 60;
+ sec /= 60;
+ minutes = sec;
+
+ StringPrintfW sp(L"%s%d:%02d", (minutes == 0 && negative) ? L"-" : L"", minutes, ABS(seconds));
+ WCSCPYN(buf, sp, buflen);
+}
+
+void TimeFmt::printHourMinSec(int sec, wchar_t *buf, int buflen, int hoursonlyifneeded)
+{
+ int hours, minutes, seconds;
+ int negative = sec < 0;
+
+ sec = ABS(sec);
+ if (buf == NULL) return;
+
+ if (sec == -1) {
+ *buf = 0;
+ return;
+ }
+
+ hours = sec / 3600;
+ sec -= hours * 3600;
+ seconds = sec % 60;
+ sec /= 60;
+ minutes = sec;
+
+ StringW sp;
+ if (hoursonlyifneeded && hours == 0)
+ sp = StringPrintfW(L"%s%d:%02d", (minutes == 0 && negative) ? L"-" : L"", minutes, seconds);
+ else
+ sp = StringPrintfW(L"%s%d:%02d:%02d", (hours == 0 && negative) ? L"-" : L"", hours, minutes, seconds);
+
+ WCSCPYN(buf, sp, buflen);
+}
+
+void TimeFmt::printTimeStamp(wchar_t *buf, int bufsize, int ts)
+{
+ if (ts == 0)
+ {
+ WCSCPYN(buf, L"Never", bufsize); // FUCKO: load from lang pack
+ return;
+ }
+
+ struct tm *tm_now;
+ tm_now = localtime((const time_t *)&ts);
+ if (tm_now == NULL)
+ {
+ *buf = 0;
+ return;
+ }
+ wcsftime(buf, bufsize, L"%a %b %Y %d %I:%M:%S %p", tm_now);
+}