compiler/libec: (#205) Corrections to integer promotions
[sdk] / ecere / src / sys / Time.ec
index e5c3ef1..a69e7de 100644 (file)
@@ -83,7 +83,7 @@ static int TIME_DayLightCompareDate(const SYSTEMTIME *date, const SYSTEMTIME *co
    {
       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;
@@ -157,7 +157,7 @@ static uint TIME_CompTimeZoneID(const TIME_ZONE_INFORMATION *pTZinfo, FILETIME *
       else if( beforeStandardDate || afterDaylightDate )
          retval = TIME_ZONE_ID_DAYLIGHT;
    }
-   else 
+   else
       retval = TIME_ZONE_ID_UNKNOWN;
    return retval;
 }
@@ -177,7 +177,7 @@ static bool TIME_GetTimezoneBias(const TIME_ZONE_INFORMATION *pTZinfo, FILETIME
    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;
@@ -210,7 +210,7 @@ import "System"
 
 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;
@@ -219,7 +219,7 @@ public class Time : double
       value = (int)(time / (60 * 60 * 24));
       if(value)
       {
-         
+
          sprintf(temp, "%d:", value);
          strcat(tempString, temp);
          time -= value * 60 * 60 * 24;
@@ -291,13 +291,20 @@ static time_t MakeTimeTfromDT(DateTime dt)
 
 public class SecSince1970 : int64
 {
-   char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+   const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+   {
+      return ((DateTime)this).OnGetString(tempString, fieldData, needClass);
+   }
+
+   bool OnGetDataFromString(const char * 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);
+      DateTime dt { };
+      if(dt.OnGetDataFromString(string))
+      {
+         this = dt;
+         return true;
+      }
+      return false;
    }
 
    // Is this required?
@@ -316,19 +323,17 @@ public class SecSince1970 : int64
 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;
@@ -371,8 +376,6 @@ public:
    };
    property SecSince1970 local
    {
-      // TOFIX: warning: 'return' with a value, in function returning void
-      set { return value.global; }
       get
       {
 #if defined(__WIN32__)
@@ -382,7 +385,7 @@ public:
          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;
@@ -424,12 +427,9 @@ public:
 public class TimeStamp32 : uint32
 {
 public:
-   char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+   const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
    {
-      DateTime t = (SecSince1970)(int)this;
-      return t.OnGetString(tempString, fieldData, needClass);
-      // TOFIX:
-      // return ((DateTime)this).OnGetString(tempString, fieldData, needClass);
+      return ((DateTime)(TimeStamp)this).OnGetString(tempString, fieldData, needClass);
    }
 
    // Is this required?
@@ -512,7 +512,7 @@ public struct DateTime
          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;
@@ -532,7 +532,7 @@ public struct DateTime
       #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;
@@ -554,7 +554,7 @@ public struct DateTime
          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;
@@ -594,7 +594,7 @@ public struct DateTime
       {
          int64 days, y;
          int rem;
-            
+
          days = value / SECS_PER_DAY;
          rem = (int)(value % SECS_PER_DAY);
 
@@ -653,8 +653,21 @@ public struct DateTime
          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;
@@ -666,13 +679,13 @@ public struct DateTime
       if(!year && !day && !month && !this.hour && !minute && !second)
          stringOutput[0] = 0;
       else
-         sprintf(stringOutput, "%s %s %2d %2d:%02d:%02d %s %04d", 
+         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];
@@ -680,7 +693,7 @@ public struct DateTime
       int c;
       bool foundDayOfTheWeek = false;
       bool foundDate = false;
-      DayOfTheWeek dayOfTheWeek;
+      DayOfTheWeek dayOfTheWeek = 0;
       int day = 0;
       int minute = 0;
       int second = 0;
@@ -690,16 +703,16 @@ public struct DateTime
       for(c = 0; c < count; c++)
       {
          int i;
-         for(i = 0; i<7; i++) 
+         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;               
+               break;
          if(i < 7) { dayOfTheWeek = (DayOfTheWeek)i; foundDayOfTheWeek = true; continue; }
 
-         for(i = 0; i<12; i++) 
+         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;               
+               break;
          if(i < 12) { month = (Month)i; continue; }
 
          if(strchr(tokens[c], ':'))
@@ -714,9 +727,9 @@ public struct DateTime
                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;
@@ -728,7 +741,7 @@ public struct DateTime
 
             continue;
          }
-         
+
          if(!foundDate)
          {
             if(strchr(tokens[c], '/') || strchr(tokens[c], '-'))