Ejemplo n.º 1
0
void GetDateNames(unsigned long	julianDate, OBJECTID oiDayOfWeek, OBJECTID oiDayOfMonth, OBJECTID oiMonth, OBJECTID	oiYear, BOOL shortNames)
{
	char					dayOfWeek[15],  month[15], dayOfMonth[15], year[15];
	DATE					date;
	LPSTR					cp;
	BOOL 					leadingZero = FALSE;
  int						i;

	date = JulianToDate(julianDate);

	if (shortNames)
		lstrcpy(dayOfWeek, g_sDayNames[DayOfTheWeek(julianDate)]);
	else
		lstrcpy(dayOfWeek, g_lDayNames[DayOfTheWeek(julianDate)]);


	// Figure out if leading zeros belong in the dayOfMonth
	cp = g_lDateProfileString;
	while(*cp)
	{
		if ((*cp|0x20) == 'd')
   	{
			for(i=0; *cp == 'd'; cp++, i++);
			if (i==2) leadingZero = TRUE;
		}
    cp++;
	}
	if (leadingZero)
		sprintf(dayOfMonth, "%02d", date.da_day);
	else
		sprintf(dayOfMonth, "%d", date.da_day);

	if (shortNames)
		lstrcpy(month, g_sMonthNames[date.da_mon-1]);
	else
		lstrcpy(month, g_lMonthNames[date.da_mon-1]);

	if (shortNames) 
	{
		date.da_year = date.da_year % 100;
		sprintf(year, "%02d", date.da_year);
	}
	else
		sprintf(year, "%d", date.da_year);

	OTextSetValueFromBuffer(oiDayOfWeek, dayOfWeek);
	OTextSetValueFromBuffer(oiMonth, month);
	OTextSetValueFromBuffer(oiDayOfMonth, dayOfMonth);
	OTextSetValueFromBuffer(oiYear, year);

}
int DateTimeAdapter::ThirdSunday( int month, int year ) {
	int firstSunday = 1;
	int dow = DayOfTheWeek(firstSunday, month, year);
	if (dow != 0) {
		firstSunday += (7 - dow);
	}
	return firstSunday + 14;
}
Ejemplo n.º 3
0
void GetDateNumbers(unsigned long	julianDate, OBJECTID	oiDayOfWeek, OBJECTID oiDayOfMonth, OBJECTID oiMonth, OBJECTID oiYear)
{
 	DATE					date;
 	
 	date = JulianToDate(julianDate);

	ONmbrSetInteger(oiDayOfWeek, (long) DayOfTheWeek(julianDate)+1, TRUE); 
	ONmbrSetInteger(oiDayOfMonth, (long) date.da_day, TRUE); 
	ONmbrSetInteger(oiMonth, (long) date.da_mon, TRUE); 
	ONmbrSetInteger(oiYear, (long) date.da_year, TRUE); 
}
bool DateTimeAdapter::IsDaylightSaving( int day, int month, int year, int dow ) {

	uint8_t dlsMode = System::DT_getAutoDaylightSaving();
	
	if (dlsMode == 1) 
		return true;  //In daylightSaving, by manual configuration
	
	if (dlsMode == 2) 
		return false; //Not in daylightSaving, by manual configuration

	if (dow == -1)
		dow = DayOfTheWeek(day, month, year);

	if (month == 11 || month == 12 || month == 1)
		return true;

	if (month == 10) {
		if (day < 15) return false;
		if (day >= 21) return true;
		// vai para o domingo anterior
		if (day - dow >= 15 && day - dow < 21)
			return true;
		else
			return false;
	}
	if (month == 2) {
		if (day < 15) return true;
		int endDay = ThirdSunday(month, year);
		if (IsCarnivalSunday(endDay, month, year)) {
			endDay += 7;
		}
		if (day >= endDay)
			return false;
		else
			return true;
	}
	return false;
}