summaryrefslogtreecommitdiffstats
path: root/src/ctdow.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <[email protected]>2021-01-13 19:26:24 +0200
committerMavridis Philippe <[email protected]>2021-01-13 19:26:24 +0200
commit8c20dc919f7d54eb48fb60f39ba5e1d466a70763 (patch)
tree44d89f278d5dd066603e5ab9c0b270bc8eb4ad51 /src/ctdow.cpp
downloadklamav-8c20dc919f7d54eb48fb60f39ba5e1d466a70763.tar.gz
klamav-8c20dc919f7d54eb48fb60f39ba5e1d466a70763.zip
Initial commit
Signed-off-by: Mavridis Philippe <[email protected]>
Diffstat (limited to 'src/ctdow.cpp')
-rw-r--r--src/ctdow.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/ctdow.cpp b/src/ctdow.cpp
new file mode 100644
index 0000000..8ce2f06
--- /dev/null
+++ b/src/ctdow.cpp
@@ -0,0 +1,98 @@
+/***************************************************************************
+ * CT Day Of Week Implementation *
+ * -------------------------------------------------------------------- *
+ * Copyright (C) 1999, Gary Meyer <[email protected]> *
+ * -------------------------------------------------------------------- *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+
+// Do not introduce any Qt or KDE dependencies into the "CT"-prefixed classes.
+// I want to be able to reuse these classes with another GUI toolkit. -GM 11/99
+
+#include "ctdow.h"
+
+string CTDayOfWeek::shortName[8] =
+{
+ "", "", "", "", "", "", "", ""
+};
+
+string CTDayOfWeek::longName[8] =
+{
+ "", "", "", "", "", "", "", ""
+};
+
+CTDayOfWeek::CTDayOfWeek(const string& tokStr) :
+ CTUnit<1,7>(tokStr)
+{
+ // Compensate for cron supporting Sunday as both 0 and 7.
+
+ if (get(0))
+ {
+ set(0,false);
+ set(7,true);
+ }
+}
+
+void CTDayOfWeek::initialize(const string &tokStr)
+{
+ CTUnit<1,7>::initialize(tokStr);
+
+ // Compensate for cron supporting Sunday as both 0 and 7.
+
+ if (get(0))
+ {
+ set(0,false);
+ set(7,true);
+ apply();
+ }
+}
+
+string CTDayOfWeek::describe() const
+{
+ initializeNames();
+ if (count() == 7)
+ return (const char*)i18n("every day ").local8Bit();
+ else if (get(1) && get(2) && get(3) && get(4) && get(5))
+ return (const char*)i18n("weekday ").local8Bit();
+ else
+ return CTUnit<1,7>::describe(shortName);
+}
+
+string CTDayOfWeek::getName(const int ndx, const bool format)
+{
+ initializeNames();
+ return (format == shortFormat) ? shortName[ndx] : longName[ndx];
+}
+
+void CTDayOfWeek::initializeNames()
+{
+ if (shortName[1].empty())
+ {
+ const string shortDOWName[8] =
+ {
+ "",
+ (const char*)i18n("Mon").local8Bit(), (const char*)i18n("Tue").local8Bit(),
+ (const char*)i18n("Wed").local8Bit(), (const char*)i18n("Thu").local8Bit(),
+ (const char*)i18n("Fri").local8Bit(), (const char*)i18n("Sat").local8Bit(),
+ (const char*)i18n("Sun").local8Bit()
+ };
+
+ const string longDOWName[8] =
+ {
+ "",
+ (const char*)i18n("Monday").local8Bit(), (const char*)i18n("Tuesday").local8Bit(),
+ (const char*)i18n("Wednesday").local8Bit(), (const char*)i18n("Thursday").local8Bit(),
+ (const char*)i18n("Friday").local8Bit(), (const char*)i18n("Saturday").local8Bit(),
+ (const char*)i18n("Sunday").local8Bit()
+ };
+
+ for (int i = 1; i <= 7; i++)
+ {
+ shortName[i] = shortDOWName[i];
+ longName[i] = longDOWName[i];
+ }
+ }
+}