aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--src/dateTime.cpp29
-rw-r--r--src/utility/datetimeUtils.cpp24
-rw-r--r--vmime/dateTime.hpp5
-rw-r--r--vmime/utility/datetimeUtils.hpp9
5 files changed, 40 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 8e18f1ed..1837a9fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,8 @@ VERSION 0.6.2-cvs
* Fixed 'stringUtils' not in namespace 'utility'.
+ * Moved 'datetime::getDayOfWeek()' to 'datetimeUtils'.
+
2005-01-01 Vincent Richard <[email protected]>
* Converted all C-style casts to C++-style casts.
diff --git a/src/dateTime.cpp b/src/dateTime.cpp
index 11a9d43d..4e42b21d 100644
--- a/src/dateTime.cpp
+++ b/src/dateTime.cpp
@@ -23,6 +23,8 @@
#include "vmime/platformDependant.hpp"
#include "vmime/parserHelpers.hpp"
+#include "vmime/utility/datetimeUtils.hpp"
+
namespace vmime
{
@@ -545,7 +547,7 @@ void datetime::generate(utility::outputStream& os, const string::size_type /* ma
const int zm = z % 60;
std::ostringstream oss;
- oss << dayNames[dayOfWeek(m_year, m_month, m_day)] << ", "
+ oss << dayNames[getWeekDay()] << ", "
<< m_day << " " << monthNames[m_month - 1] << " " << m_year
<< " " << std::setfill('0') << std::setw(2) << m_hour << ":"
<< std::setfill('0') << std::setw(2) << m_minute << ":"
@@ -673,30 +675,6 @@ void datetime::setDate(const int year, const int month, const int day)
}
-const int datetime::dayOfWeek(const int year, const int month, const int day)
-{
- int y = year;
- int m = month;
-
- // From RFC-3339 - Appendix B. Day of the Week
-
- // Adjust months so February is the last one
- m -= 2;
-
- if (m < 1)
- {
- m += 12;
- --y;
- }
-
- // Split by century
- const int cent = y / 100;
- y %= 100;
-
- return (((26 * m - 2) / 10 + day + y + (y >> 2) + (cent >> 2) + 5 * cent) % 7);
-}
-
-
const datetime datetime::now()
{
return (platformDependant::getHandler()->getCurrentLocalTime());
@@ -722,6 +700,7 @@ const int datetime::getHour() const { return (m_hour); }
const int datetime::getMinute() const { return (m_minute); }
const int datetime::getSecond() const { return (m_second); }
const int datetime::getZone() const { return (m_zone); }
+const int datetime::getWeekDay() const { return (utility::datetimeUtils::getDayOfWeek(m_year, m_month, m_day)); }
void datetime::setYear(const int year) { m_year = year; }
void datetime::setMonth(const int month) { m_month = std::min(std::max(month, 1), 12); }
diff --git a/src/utility/datetimeUtils.cpp b/src/utility/datetimeUtils.cpp
index 2c9d6d08..020e69c2 100644
--- a/src/utility/datetimeUtils.cpp
+++ b/src/utility/datetimeUtils.cpp
@@ -217,5 +217,29 @@ const int datetimeUtils::getDaysInMonth(const int year, const int month)
}
+const int datetimeUtils::getDayOfWeek(const int year, const int month, const int day)
+{
+ int y = year;
+ int m = month;
+
+ // From RFC-3339 - Appendix B. Day of the Week
+
+ // Adjust months so February is the last one
+ m -= 2;
+
+ if (m < 1)
+ {
+ m += 12;
+ --y;
+ }
+
+ // Split by century
+ const int cent = y / 100;
+ y %= 100;
+
+ return (((26 * m - 2) / 10 + day + y + (y >> 2) + (cent >> 2) + 5 * cent) % 7);
+}
+
+
} // utility
} // vmime
diff --git a/vmime/dateTime.hpp b/vmime/dateTime.hpp
index 10df78d0..19d65ee9 100644
--- a/vmime/dateTime.hpp
+++ b/vmime/dateTime.hpp
@@ -192,6 +192,7 @@ public:
const int getMinute() const;
const int getSecond() const;
const int getZone() const;
+ const int getWeekDay() const;
void getTime(int& hour, int& minute, int& second, int& zone) const;
void getTime(int& hour, int& minute, int& second) const;
@@ -222,10 +223,6 @@ public:
const std::vector <const component*> getChildComponents() const;
-private:
-
- static const int dayOfWeek(const int year, const int month, const int day);
-
public:
using component::parse;
diff --git a/vmime/utility/datetimeUtils.hpp b/vmime/utility/datetimeUtils.hpp
index 1a64bda5..6cee67b1 100644
--- a/vmime/utility/datetimeUtils.hpp
+++ b/vmime/utility/datetimeUtils.hpp
@@ -65,6 +65,15 @@ public:
* @return local time and date
*/
static const datetime universalTimeToLocalTime(const datetime& date, const int zone);
+
+ /** Return the day of the week from the specified date.
+ *
+ * @param year year in 4-digit format
+ * @param month month (1-12), January is 1, December is 12 (see datetime::Months enum)
+ * @param day month day (1-31)
+ * @return the day of the week, Sunday is 0, Monday is 1 (see datetime::DaysOfWeek enum)
+ */
+ static const int getDayOfWeek(const int year, const int month, const int day);
};