namespace sys;
-import "instance"
-
+#define set _set
#define Date _Date
#define uint _uint
#define Method _Method
#define uint64 _uint64
#define Alignment _Alignment
+#undef __BLOCKS__
+
#if defined(__WIN32__)
#define WIN32_LEAN_AND_MEAN
+#define String String_
#include <windows.h>
+#undef String
#include <mmsystem.h>
#elif defined(__unix__) || defined(__APPLE__)
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
+#undef set
#undef uint
#undef int64
#undef uint64
#undef Size
#undef Date
+import "instance"
+
define EPOCH_YEAR = 1970;
define EPOCH_WEEKDAY = thursday;
static define SECS_PER_HOUR = 60 * 60;
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
-char daysNames[7][4] =
-{
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-};
-char monthsNames[12][4] =
-{
- "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
#if defined(__WIN32__)
#define LL2FILETIME( ll, pft ) (pft)->dwLowDateTime = (UINT)(ll); (pft)->dwHighDateTime = (UINT)((ll) >> 32);
{
WORD First;
int weekofmonth = compareDate->wDay;
- First = ( 6 + compareDate->wDayOfWeek - date->wDayOfWeek + date->wDay ) % 7 + 1;
+ First = (WORD)(( 6 + compareDate->wDayOfWeek - date->wDayOfWeek + date->wDay ) % 7 + 1);
limit_day = First + 7 * (weekofmonth - 1);
if(limit_day > monthLengths[date->wMonth==2 && ISLEAP(date->wYear)][date->wMonth - 1])
limit_day -= 7;
else if( beforeStandardDate || afterDaylightDate )
retval = TIME_ZONE_ID_DAYLIGHT;
}
- else
+ else
retval = TIME_ZONE_ID_UNKNOWN;
return retval;
}
return true;
}
-static bool _TzSpecificLocalTimeToSystemTime(LPTIME_ZONE_INFORMATION lpTimeZoneInformation, LPSYSTEMTIME lpLocalTime, LPSYSTEMTIME lpUniversalTime)
+static bool _TzSpecificLocalTimeToSystemTime(LPTIME_ZONE_INFORMATION lpTimeZoneInformation, LPSYSTEMTIME lpLocalTime, LPSYSTEMTIME lpUniversalTime)
{
FILETIME ft;
LONG lBias;
public class Time : double
{
- char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+ const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
Time time = this;
int value;
value = (int)(time / (60 * 60 * 24));
if(value)
{
-
+
sprintf(temp, "%d:", value);
strcat(tempString, temp);
time -= value * 60 * 60 * 24;
public class SecSince1970 : int64
{
- char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+ const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
- if(this || !this)
+ return ((DateTime)this).OnGetString(tempString, fieldData, needClass);
+ }
+
+ bool OnGetDataFromString(const char * string)
+ {
+ DateTime dt { };
+ if(dt.OnGetDataFromString(string))
{
- // TOFIX: passing argument 2 of '__ecereProp___ecereNameSpace__ecere__sys__DateTime_Set___ecereNameSpace__ecere__sys__SecSince1970' makes integer from pointer without a cast
- DateTime t = this;
- return t.OnGetString(tempString, fieldData, needClass);
- // TOFIX:
- // return ((DateTime)this).OnGetString(tempString, fieldData, needClass);
+ this = dt;
+ return true;
}
- return tempString;
+ return false;
}
// Is this required?
public:
property SecSince1970 global
{
- // TOFIX: 'return' with a value, in function returning void
- set { return value.local; }
get
{
#if defined(__WIN32__)
SYSTEMTIME localTime, systemTime;
- FILETIME fileTime, localFileTime;
+ //FILETIME fileTime, localFileTime;
DateTime input, global;
input = this;
localTime.wYear = (short)input.year;
- localTime.wMonth = (short)input.month + 1;
+ localTime.wMonth = (short)(input.month + 1);
localTime.wDay = (short)input.day;
localTime.wHour = (short)input.hour;
localTime.wMinute = (short)input.minute;
};
property SecSince1970 local
{
- // TOFIX: warning: 'return' with a value, in function returning void
- set { return value.global; }
get
{
#if defined(__WIN32__)
utc = this;
systemTime.wYear = (short)utc.year;
- systemTime.wMonth = (short)utc.month + 1;
+ systemTime.wMonth = (short)(utc.month + 1);
systemTime.wDay = (short)utc.day;
systemTime.wHour = (short)utc.hour;
systemTime.wMinute = (short)utc.minute;
public class TimeStamp32 : uint32
{
public:
- char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+ const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
- if(this || !this)
- {
- DateTime t = (SecSince1970)(int)this;
- return t.OnGetString(tempString, fieldData, needClass);
- // TOFIX:
- // return ((DateTime)this).OnGetString(tempString, fieldData, needClass);
- }
- return tempString;
+ return ((DateTime)(TimeStamp)this).OnGetString(tempString, fieldData, needClass);
}
// Is this required?
FILETIME fileTime, localFileTime;
localTime.wYear = (short)year;
- localTime.wMonth = (short)month + 1;
+ localTime.wMonth = (short)(month + 1);
localTime.wDay = (short)day;
localTime.wHour = (short)hour;
localTime.wMinute = (short)minute;
#else
struct tm tm;
//time_t t = (time_t)(SecSince1970)this;
- time_t t = MakeTimeTfromDT(this);
+ time_t t = MakeTimeTfromDT(this);
gmtime_r(&t, &tm);
value.year = tm.tm_year + 1900;
value.month = (Month)tm.tm_mon;
SYSTEMTIME systemTime, localTime;
systemTime.wYear = (short)year;
- systemTime.wMonth = (short)month + 1;
+ systemTime.wMonth = (short)(month + 1);
systemTime.wDay = (short)day;
systemTime.wHour = (short)hour;
systemTime.wMinute = (short)minute;
{
int64 days, y;
int rem;
-
+
days = value / SECS_PER_DAY;
rem = (int)(value % SECS_PER_DAY);
return 0;
}
};
+ property Date
+ {
+ set
+ {
+ year = value.year;
+ month = value.month;
+ day = value.day;
+ hour = 0;
+ minute = 0;
+ second = 0;
+ }
+ get { value = Date { year, month, day }; }
+ }
- char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
+ const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
{
static const char ampm[2][3] = { "AM", "PM" };
int hour = this.hour;
if(!year && !day && !month && !this.hour && !minute && !second)
stringOutput[0] = 0;
else
- sprintf(stringOutput, "%s %s %2d %2d:%02d:%02d %s %04d",
- daysNames[dayOfTheWeek], monthsNames[month], day, hour, minute, second, ampm[pm], year);
+ sprintf(stringOutput, "%s %s %2d %2d:%02d:%02d %s %04d",
+ shortDaysNames[dayOfTheWeek], shortMonthsNames[month], day, hour, minute, second, ampm[pm], year);
return stringOutput;
}
- bool OnGetDataFromString(char * string)
+ bool OnGetDataFromString(const char * string)
{
char * s = CopyString(string);
char * tokens[20];
int c;
bool foundDayOfTheWeek = false;
bool foundDate = false;
- DayOfTheWeek dayOfTheWeek;
+ DayOfTheWeek dayOfTheWeek = 0;
int day = 0;
int minute = 0;
int second = 0;
for(c = 0; c < count; c++)
{
int i;
- for(i = 0; i<7; i++)
- if(!strcmpi(tokens[c], daysNames[i]) || !strcmpi(tokens[c], longDaysNames[i]))
- break;
+ for(i = 0; i<7; i++)
+ if(!strcmpi(tokens[c], shortDaysNames[i]) || !strcmpi(tokens[c], longDaysNames[i]) ||
+ !strcmpi(tokens[c], enShortDaysNames[i]) || !strcmpi(tokens[c], enLongDaysNames[i]))
+ break;
if(i < 7) { dayOfTheWeek = (DayOfTheWeek)i; foundDayOfTheWeek = true; continue; }
- for(i = 0; i<12; i++)
- if(!strcmpi(tokens[c], monthsNames[i]) || !strcmpi(tokens[c], longMonthsNames[i]))
- break;
+ for(i = 0; i<12; i++)
+ if(!strcmpi(tokens[c], shortMonthsNames[i]) || !strcmpi(tokens[c], longMonthsNames[i]) ||
+ !strcmpi(tokens[c], enShortMonthsNames[i]) || !strcmpi(tokens[c], enLongMonthsNames[i]))
+ break;
if(i < 12) { month = (Month)i; continue; }
if(strchr(tokens[c], ':'))
else if(!strcmpi(subTokens[t], "pm")) pm = true;
else if(t-am-pm == 0) hour = atoi(subTokens[t]);
else if(t-am-pm == 1) minute = atoi(subTokens[t]);
- else if(t-am-pm == 2) second = atoi(subTokens[t]);
+ else if(t-am-pm == 2) second = atoi(subTokens[t]);
}
-
+
if(c < count - 1)
{
if(!strcmpi(tokens[c+1], "am")) am = true;
continue;
}
-
+
if(!foundDate)
{
if(strchr(tokens[c], '/') || strchr(tokens[c], '-'))
weWant = (SecSince1970)this + (int)(dayOfTheWeek - this.dayOfTheWeek) * 24 * 60 * 60;
this = (DateTime)weWant;
}
- else if(!strcmpi(s, "today") || !strcmpi(s, "now"))
+ else if(!strcmpi(s, "today") || !strcmpi(s, $"today") ||
+ !strcmpi(s, "now") || !strcmpi(s, $"now"))
GetLocalTime();
- else if(!strcmpi(s, "tomorrow"))
+ else if(!strcmpi(s, "tomorrow") || !strcmpi(s, $"tomorrow"))
{
SecSince1970 weWant;
GetLocalTime();
weWant = (SecSince1970)this + 24 * 60 * 60;
this = (DateTime)weWant;
}
- else if(!strcmpi(s, "yesterday"))
+ else if(!strcmpi(s, "yesterday") || !strcmpi(s, $"yesterday"))
{
SecSince1970 weWant;
GetLocalTime();
if(!secbase)
{
- secbase = tp.tv_sec;
+ secbase = (int)tp.tv_sec;
return tp.tv_usec / 1000000.0;
}
return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0;