conversion to/from DOS date/time (patch 627575)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17709 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -235,6 +235,7 @@ values were correct as constructors can not return an error code.
|
||||
\helpref{Set(double jdn)}{wxdatetimesetjdn}\\
|
||||
\helpref{Set(h, m, s, ms)}{wxdatetimesettime}\\
|
||||
\helpref{Set(day, mon, year, h, m, s, ms)}{wxdatetimesetdate}\\
|
||||
\helpref{SetFromDOS(unsigned long ddt)}{wxdatetimesetfromdos}\\
|
||||
\helpref{ResetTime}{wxdatetimeresettime}\\
|
||||
\helpref{SetYear}{wxdatetimesetyear}\\
|
||||
\helpref{SetMonth}{wxdatetimesetmonth}\\
|
||||
@@ -268,7 +269,8 @@ some more complicated calculations to find the answer are under the
|
||||
\helpref{GetWeekOfMonth}{wxdatetimegetweekofmonth}\\
|
||||
\helpref{GetYearDay}{wxdatetimegetyearday}\\
|
||||
\helpref{IsWorkDay}{wxdatetimeisworkday}\\
|
||||
\helpref{IsGregorianDate}{wxdatetimeisgregoriandate}
|
||||
\helpref{IsGregorianDate}{wxdatetimeisgregoriandate}\\
|
||||
\helpref{GetAsDOS}{wxdatetimegetasdos}
|
||||
|
||||
\membersection{Date comparison}
|
||||
|
||||
@@ -882,6 +884,24 @@ Returns {\tt TRUE} if the given date os later than the date of adoption of the
|
||||
Gregorian calendar in the given country (and hence the Gregorian calendar
|
||||
calculations make sense for it).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%% dos date and time format %%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
\membersection{wxDateTime::SetFromDOS}\label{wxdatetimesetfromdos}
|
||||
|
||||
\func{wxDateTime\&}{Set}{\param{unsigned long }{ddt}}
|
||||
|
||||
Sets the date from the date and time in
|
||||
\urlref{DOS}{http://developer.novell.com/ndk/doc/smscomp/index.html?page=/ndk/doc/smscomp/sms\_docs/data/hc2vlu5i.html}
|
||||
format.
|
||||
|
||||
\membersection{wxDateTime::GetAsDOS}\label{wxdatetimegetasdos}
|
||||
|
||||
\constfunc{unsigned long}{GetAsDOS}{\void}
|
||||
|
||||
Returns the date and time in
|
||||
\urlref{DOS}{http://developer.novell.com/ndk/doc/smscomp/index.html?page=/ndk/doc/smscomp/sms\_docs/data/hc2vlu5i.html}
|
||||
format.
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%% comparison %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
\membersection{wxDateTime::IsEqualTo}\label{wxdatetimeisequalto}
|
||||
|
@@ -851,6 +851,15 @@ public:
|
||||
// adoption of the Gregorian calendar is simply unknown.
|
||||
bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
|
||||
|
||||
// dos date and time format
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// set from the DOS packed format
|
||||
wxDateTime& SetFromDOS(unsigned long ddt);
|
||||
|
||||
// pack the date in DOS format
|
||||
unsigned long GetAsDOS() const;
|
||||
|
||||
// comparison (see also functions below for operator versions)
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
@@ -1247,6 +1247,82 @@ wxDateTime& wxDateTime::ResetTime()
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DOS Date and Time Format functions
|
||||
// ----------------------------------------------------------------------------
|
||||
// the dos date and time value is an unsigned 32 bit value in the format:
|
||||
// YYYYYYYMMMMDDDDDhhhhhmmmmmmsssss
|
||||
//
|
||||
// Y = year offset from 1980 (0-127)
|
||||
// M = month (1-12)
|
||||
// D = day of month (1-31)
|
||||
// h = hour (0-23)
|
||||
// m = minute (0-59)
|
||||
// s = bisecond (0-29) each bisecond indicates two seconds
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxDateTime& wxDateTime::SetFromDOS(unsigned long ddt)
|
||||
{
|
||||
struct tm tm;
|
||||
|
||||
long year = ddt & 0xFE000000;
|
||||
year >>= 25;
|
||||
year += 80;
|
||||
tm.tm_year = year;
|
||||
|
||||
long month = ddt & 0x1E00000;
|
||||
month >>= 21;
|
||||
month -= 1;
|
||||
tm.tm_mon = month;
|
||||
|
||||
long day = ddt & 0x1F0000;
|
||||
day >>= 16;
|
||||
tm.tm_mday = day;
|
||||
|
||||
long hour = ddt & 0xF800;
|
||||
hour >>= 11;
|
||||
tm.tm_hour = hour;
|
||||
|
||||
long minute = ddt & 0x7E0;
|
||||
minute >>= 5;
|
||||
tm.tm_min = minute;
|
||||
|
||||
long second = ddt & 0x1F;
|
||||
tm.tm_sec = second * 2;
|
||||
|
||||
return Set(mktime(&tm));
|
||||
}
|
||||
|
||||
unsigned long wxDateTime::GetAsDOS() const
|
||||
{
|
||||
unsigned long ddt;
|
||||
time_t ticks = GetTicks();
|
||||
struct tm *tm = localtime(&ticks);
|
||||
|
||||
long year = tm->tm_year;
|
||||
year -= 80;
|
||||
year <<= 25;
|
||||
|
||||
long month = tm->tm_mon;
|
||||
month += 1;
|
||||
month <<= 21;
|
||||
|
||||
long day = tm->tm_mday;
|
||||
day <<= 16;
|
||||
|
||||
long hour = tm->tm_hour;
|
||||
hour <<= 11;
|
||||
|
||||
long minute = tm->tm_min;
|
||||
minute <<= 5;
|
||||
|
||||
long second = tm->tm_sec;
|
||||
second /= 2;
|
||||
|
||||
ddt = year | month | day | hour | minute | second;
|
||||
return ddt;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// time_t <-> broken down time conversions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user