Moved 'datetime::getDayOfWeek()' to 'datetimeUtils'.

This commit is contained in:
Vincent Richard 2005-01-02 21:37:53 +00:00
parent 0e9696e40d
commit 29035ed41e
5 changed files with 40 additions and 29 deletions

View File

@ -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 <vincent@vincent-richard.net>
* Converted all C-style casts to C++-style casts.

View File

@ -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); }

View File

@ -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

View File

@ -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;

View File

@ -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);
};