Пример #1
0
BOOL CMyDateEdit::CheckChar(UINT nChar)
{
	int nTime = 0;
	//如果不使用掩码,则返回
	if(!m_bUseMask)	return TRUE;
	//如果是控制字符,则返回
	if(!isprint(nChar)) return TRUE;
	if(!isdigit(nChar))	
	{
		MessageBeep((UINT)-1);
		return FALSE;
	}
	//如果存在选择区域,则取消选择
	int startPos,endPos;
	GetSel(startPos,endPos);
	SetSel(-1,0);
	//重新选中原选择区域的第一个字符
	SetSel(startPos,startPos);
	GetSel(startPos,endPos);
	//确保字符串的长度不超过掩码的长度
	if(endPos>=m_strMask.GetLength())
	{
		MessageBeep((UINT)-1);
		return FALSE;
	}
	//时间格式
	if(m_isTime)
	{
		if(!CheckTime(nChar,startPos,endPos))
		{
			return FALSE;
		}
	}
	//日期格式
	if(m_isDate)
	{
		if(!CheckDate(nChar,startPos,startPos))
		{
			return FALSE;
		}
	}
	if(m_isDateTime)
	{
		if(!CheckDate(nChar,startPos,startPos))
		{
			return FALSE;
		}
		if(!CheckTime(nChar,startPos,startPos))
		{
			return FALSE;
		}
	}
    return TRUE;
}
Пример #2
0
/*----------------------------------------------------------------------
|   NPT_DateTime::ToTimeStamp
+---------------------------------------------------------------------*/
NPT_Result
NPT_DateTime::ToTimeStamp(NPT_TimeStamp& timestamp) const
{
    // default value
    timestamp.SetNanos(0);
    
    // check bounds
    NPT_Result result = CheckDate(*this);
    if (NPT_FAILED(result)) return result;

    // compute the number of days elapsed since 1900
    NPT_UInt32 days = ElapsedDaysSince1900(*this);

    // compute the number of nanoseconds
    NPT_Int64 seconds = (NPT_Int64)days      * (24*60*60) + 
                        (NPT_Int64)m_Hours   * (60*60) +
                        (NPT_Int64)m_Minutes * (60) + 
                        (NPT_Int64)m_Seconds;
    seconds -= (NPT_Int64)m_TimeZone*60;

    // adjust to the number of seconds since 1900
    seconds -= (NPT_Int64)NPT_SECONDS_PER_YEAR*70 + 
        (NPT_Int64)(17*NPT_SECONDS_PER_DAY); // 17 leap year between 1900 and 1970

    timestamp.FromNanos(seconds * 1000000000 + m_NanoSeconds);

    return NPT_SUCCESS;
}
Пример #3
0
	Date (int year = 1900, int month = 1, int day = 1)
		:_year(year)
		,_month(month)
		,_day(day)
	{
		// 检查如果输入参数是非法时间,则初始化为1900-1-1
		assert(CheckDate());
	}
Пример #4
0
gboolean ReadVCALDateTime(const char *Buffer, GSM_DateTime *dt)
{
	time_t timestamp;
	char year[5]="", month[3]="", day[3]="", hour[3]="", minute[3]="", second[3]="";

	memset(dt,0,sizeof(GSM_DateTime));

	/* YYYY-MM-DD is invalid, though used */
	if (sscanf(Buffer, "%d-%d-%d", &dt->Year, &dt->Month, &dt->Day) == 3) {
		goto checkdt;
	}

	if (strlen(Buffer) < 8) {
		return FALSE;
	}

	strncpy(year, 	Buffer, 	4);
	strncpy(month, 	Buffer+4, 	2);
	strncpy(day, 	Buffer+6, 	2);
	dt->Year	= atoi(year);
	dt->Month	= atoi(month);
	dt->Day		= atoi(day);

	if (Buffer[8] == 'T') {
		if (strlen(Buffer + 9) < 6) return FALSE;

		strncpy(hour, 	Buffer+9,	2);
		strncpy(minute, Buffer+11,	2);
		strncpy(second, Buffer+13,	2);
		dt->Hour	= atoi(hour);
		dt->Minute	= atoi(minute);
		dt->Second	= atoi(second);

		/**
		 * @todo Handle properly timezone information
		 */
		if (Buffer[15] == 'Z') dt->Timezone = 0; /* Z = ZULU = GMT */
	}
checkdt:

	if (!CheckTime(dt)) {
		dbgprintf(NULL, "incorrect date %d-%d-%d %d:%d:%d\n",dt->Day,dt->Month,dt->Year,dt->Hour,dt->Minute,dt->Second);
		return FALSE;
	}
	if (dt->Year!=0) {
		if (!CheckDate(dt)) {
			dbgprintf(NULL, "incorrect date %d-%d-%d %d:%d:%d\n",dt->Day,dt->Month,dt->Year,dt->Hour,dt->Minute,dt->Second);
			return FALSE;
		}
	}

	if (dt->Timezone != 0) {
		timestamp = Fill_Time_T(*dt) + dt->Timezone;
		Fill_GSM_DateTime(dt, timestamp);
	}

	return TRUE;
}
Пример #5
0
int main(int argc, char *argv[])
{
	
#if TARGET_OS_MAC
	#if USE_TIMEBOMB
		CheckDate();
	#endif /* USE_TIMEBOMB */
	return FskCocoaMain(kFskMainNetwork | kFskMainServer, argc, argv);
#else
	int err = (int)doMain(kFskMainNetwork | kFskMainServer, argc, argv);
#if TARGET_OS_LINUX
	fprintf(stderr, "successfully exited with error code %d.\n", err);
#endif
	return err;
#endif
}
Пример #6
0
uint GetEndOfMonth(uint y, uint m)
{
#if 1
	uint d;

	Day2Date(Date2Day(y, m, 32), NULL, NULL, &d);
	return 32 - d;
#else // same, old
	uint d;

	for(d = 31; 28 < d ; d--)
		if(CheckDate(y, m, d))
			break;

	return d;
#endif
}
Пример #7
0
/**
 * Recalculates struct tm content. We can not use mktime directly, as it
 * works only for dates > 1970. Day of week calculation is nased on article
 * in Polish PC-Kurier 8/1998 page 104.
 *
 * @see http://www.pckurier.pl
 */
int RecalcDateTime(struct tm *st, const int year, const int month, const int day, const int hour, const int minute, const int second)
{
	const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
	int i, p, q, r;
	GSM_DateTime Date;

	Date.Year	= year;
	Date.Month	= month;
	Date.Day	= day;
	Date.Hour	= hour;
	Date.Minute	= minute;
	Date.Second	= second;
	Date.Timezone	= 0;

	if (!CheckDate(&Date) || !CheckTime(&Date)) return 0;

	memset(st, 0, sizeof(*st));

	/* Calculate day of year */
	st->tm_yday = day;
	for (i = 0; i < month - 1; i++)
		st->tm_yday += days[i];

	/* Calculate day of week */
	p = (14 - month) / 12;
	q = month + 12 * p - 2;
	r = year - p;
	st->tm_wday = (day + (31 * q) / 12 + r + r / 4 - r / 100 + r / 400) % 7;


	st->tm_hour = hour;
	st->tm_min = minute;
	st->tm_sec = second;
	st->tm_year = year - 1900;
	st->tm_mon = month - 1;
	st->tm_mday = day;

	st->tm_isdst = -1; /* FIXME */

	return 1;
}
Пример #8
0
// -------------------------------------------------------------------------------------------------------------------------------------------------------
void LogClass::LogAddStr(COLORREF colorText, LPCCH pText)
{
	GetCurrentDate(&m_SysTime);
	// -----
	m_iTextLength = sprintf(m_LogBuff, "[%02d:%02d:%02d]  %s\0", m_SysTime.wHour, m_SysTime.wMinute, m_SysTime.wSecond, pText);
	// -----
	LogTextAdd(colorText, m_LogBuff, m_iTextLength);
	// -----
	if ( CheckDate(&m_SysTime, &m_Prev_SysTime) == false )
	{
		sprintf(m_szFilePath, "LOG_%02d.%02d.%04d[%s].log\0", m_SysTime.wDay, m_SysTime.wMonth, m_SysTime.wYear, SOFT_NAME);
		// -----
		GetCurrentDate(&m_Prev_SysTime);
		// -----
		WriteDataInFile(m_LogBuffFile, m_iTextLengthKeep);
		// -----
		memset(m_LogBuffFile, 0, sizeof(m_LogBuffFile));
		m_iTextLengthKeep	= 0;
	}
	else
	{
		if( m_iTextLengthKeep + m_iTextLength >= LOG_TEXT_FILE_LENGTH )
		{
			sprintf(m_szFilePath, "LOG_%02d.%02d.%04d[%s].log\0", m_Prev_SysTime.wDay, m_Prev_SysTime.wMonth, m_Prev_SysTime.wYear, SOFT_NAME);
			// -----
			WriteDataInFile(m_LogBuffFile, m_iTextLengthKeep);
			// -----
			memset(m_LogBuffFile, 0, sizeof(m_LogBuffFile));
			m_iTextLengthKeep	= 0;
		}
	}
	// ----
	memcpy(& m_LogBuffFile[m_iTextLengthKeep], m_LogBuff, m_iTextLength);
	// ----
	m_iTextLengthKeep	+= m_iTextLength;
	// ----
	sprintf(& m_LogBuffFile[m_iTextLengthKeep], "\n");
	// ----
	m_iTextLengthKeep	+= 1;
}
Пример #9
0
int UserOnlineSettingChanged(WPARAM hContact, LPARAM lParam)
{
	DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam;

	char *szProto = GetContactProto(hContact);
	if(hContact == NULL || mir_strcmp(cws->szSetting,"Status")) return 0;
	if (szProto && (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM)) {
		int newStatus = cws->value.wVal;
		int oldStatus = db_get_w(hContact,"UserOnline","OldStatus",ID_STATUS_OFFLINE);
		
		if (newStatus != oldStatus && hContact != NULL && newStatus != ID_STATUS_OFFLINE) {
			DBVARIANT dbv;
			if (!db_get_ts(hContact, modname, "PounceMsg", &dbv) && (dbv.ptszVal[0] != '\0')) {
				// check my status
				if (statusCheck(db_get_w(hContact, modname, "SendIfMyStatusIsFLAG", 0), CallProtoService(szProto, PS_GETSTATUS,0,0)) 
				// check the contacts status
				&& statusCheck(db_get_w(hContact, modname, "SendIfTheirStatusIsFLAG", 0), newStatus)) {
					// check if we r giving up after x days
					if (CheckDate(hContact)) {
						if (db_get_w(hContact, modname, "ConfirmTimeout", 0)) {
							SendPounceDlgProcStruct *spdps = (SendPounceDlgProcStruct *)mir_alloc(sizeof(SendPounceDlgProcStruct));
							TCHAR *message = mir_tstrdup(dbv.ptszVal); // will get free()ed in the send confirm window proc
							spdps->hContact = hContact;
							spdps->message = message;
							CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CONFIRMSEND), 0, SendPounceDlgProc, (LPARAM)spdps);
							// set the confirmation window to send the msg when the timeout is done
							mir_free(message);
						}
						else SendPounce(dbv.ptszVal, hContact);
					}
				}
				db_free(&dbv);
			}
		}
	}
	return 0;
}
Пример #10
0
        /* Check the Tag Details of this current game against those in
         * the wanted lists. Check all details apart from any ECO
         * tag as this is checked separately by CheckECOTag.
         * An empty list implies that there is no restriction on
         * the values in the corresponding tag field.
         * In consequence, completely empty lists imply that all
         * games reaching this far are wanted.
         * Return TRUE if wanted, FALSE otherwise.
         */
Boolean
CheckTagDetailsNotECO(char *Details[],int num_details)
{   Boolean wanted = TRUE;
    int tag;

    if(GlobalState.check_tags){
        /* Sanity check. */
        if(num_details < tag_list_length){
            fprintf(GlobalState.logfile,
                   "Internal error: mismatch in tag set lengths in ");
            fprintf(GlobalState.logfile,
                   "CheckTagDetailsNotECO: %d vs %d\n",
                   num_details,tag_list_length);
            exit(1);
        }

        /* PSEUDO_PLAYER_TAG and PSEUDO_ELO_TAG are treated differently,
         * since they have the effect of or-ing together the WHITE_ and BLACK_ lists.
         * Otherwise, different tag lists are and-ed.
         */
        if(TagLists[PSEUDO_PLAYER_TAG].num_used_elements != 0){
            /* Check both the White and Black lists. */
            if(Details[WHITE_TAG] != NULL){
                wanted = CheckList(WHITE_TAG,Details[WHITE_TAG],
                                    &TagLists[PSEUDO_PLAYER_TAG]);
                /* If we didn't find a player there, try for the opponent. */
                if(!wanted && (Details[BLACK_TAG] != NULL)){
                    wanted = CheckList(BLACK_TAG,Details[BLACK_TAG],
                                    &TagLists[PSEUDO_PLAYER_TAG]);
                }
            }
            else if(Details[BLACK_TAG] != NULL){
                wanted = CheckList(BLACK_TAG,Details[BLACK_TAG],
                                    &TagLists[PSEUDO_PLAYER_TAG]);
            }
            else{
                wanted = FALSE;
            }
        }
        else if(TagLists[PSEUDO_ELO_TAG].num_used_elements != 0){
            /* Check both the White and Black lists. */
            if(Details[WHITE_ELO_TAG] != NULL){
                wanted = CheckElo(Details[WHITE_ELO_TAG],
                                    &TagLists[PSEUDO_ELO_TAG]);
                /* If we didn't find a player there, try for the opponent. */
                if(!wanted && (Details[BLACK_ELO_TAG] != NULL)){
                    wanted = CheckElo(Details[BLACK_ELO_TAG],
                                    &TagLists[PSEUDO_ELO_TAG]);
                }
            }
            else if(Details[BLACK_ELO_TAG] != NULL){
                wanted = CheckElo(Details[BLACK_ELO_TAG],
                                    &TagLists[PSEUDO_ELO_TAG]);
            }
            else{
                wanted = FALSE;
            }
        }
        else{
            /* No PSEUDO_*_TAG info to check. */
        }

        /* Check the remaining tags in turn as long as we still have a match. */
        for(tag = 0; (tag < tag_list_length) && wanted; tag++){
            if(tag == PSEUDO_PLAYER_TAG){
            }
            else if(tag == PSEUDO_ELO_TAG){
            }
            else if(tag == ECO_TAG){
                /* This is handled separately. */
            }
            else if(TagLists[tag].num_used_elements != 0){
                if(Details[tag] != NULL){
                    if(tag == DATE_TAG){
                        wanted = CheckDate(Details[tag],&TagLists[tag]);
                    }
                    else if((tag == WHITE_ELO_TAG) || (tag == BLACK_ELO_TAG)){
                        wanted = CheckElo(Details[tag],&TagLists[tag]);
                    }
                    else{
                        wanted = CheckList(tag,Details[tag],&TagLists[tag]);
                    }
                }
                else{
                    /* Required tag not present. */
                    wanted = FALSE;
                }
            }
            else{
                /* Not used. */
            }
        }
    }
    return wanted;
}
Пример #11
0
/*----------------------------------------------------------------------
|   NPT_DateTime::FromString
+--------------------------------------------------------------------*/
NPT_Result
NPT_DateTime::FromString(const char* date, Format format)
{
    if (date == NULL || date[0] == '\0') return NPT_ERROR_INVALID_PARAMETERS;
    
    // create a local copy to work with
    NPT_String workspace(date);
    char* input = workspace.UseChars();
    NPT_Size input_size = workspace.GetLength();
    
    switch (format) {
      case FORMAT_W3C: {
        if (input_size < 17 && input_size != 10) return NPT_ERROR_INVALID_SYNTAX;

        // check separators
        if (input[4] != '-' || 
            input[7] != '-') {
            return NPT_ERROR_INVALID_SYNTAX;
        }
         
        // replace separators with terminators
        input[4] = input[7] = '\0';
        
        bool no_seconds = true;
        if (input_size > 10) {
            if (input[10] != 'T' || 
                input[13] != ':') {
                return NPT_ERROR_INVALID_SYNTAX;
            }
           input[10] = input[13] = '\0';
            if (input[16] == ':') {
                input[16] = '\0';
                no_seconds = false;
                if (input_size < 20) return NPT_ERROR_INVALID_SYNTAX;
            } else {
                m_Seconds = 0;
            }
        }
          
    
        // parse CCYY-MM-DD fields
        if (NPT_FAILED(NPT_ParseInteger(input,    m_Year,    false)) ||
            NPT_FAILED(NPT_ParseInteger(input+5,  m_Month,   false)) ||
            NPT_FAILED(NPT_ParseInteger(input+8,  m_Day,     false))) {
            return NPT_ERROR_INVALID_SYNTAX;
        }

        // parse remaining fields if any
        if (input_size > 10) {
            // parse the timezone part
            if (input[input_size-1] == 'Z') {
                m_TimeZone = 0;
                input[input_size-1] = '\0';
            } else if (input[input_size-6] == '+' || input[input_size-6] == '-') {
                if (input[input_size-3] != ':') return NPT_ERROR_INVALID_SYNTAX;
                input[input_size-3] = '\0';
                unsigned int hh, mm;
                if (NPT_FAILED(NPT_ParseInteger(input+input_size-5, hh, false)) ||
                    NPT_FAILED(NPT_ParseInteger(input+input_size-2, mm, false))) {
                    return NPT_ERROR_INVALID_SYNTAX;
                }
                if (hh > 59 || mm > 59) return NPT_ERROR_INVALID_SYNTAX;
                m_TimeZone = hh*60+mm;
                if (input[input_size-6] == '-') m_TimeZone = -m_TimeZone;
                input[input_size-6] = '\0';
            }
            
            // parse fields
            if (NPT_FAILED(NPT_ParseInteger(input+11, m_Hours,   false)) ||
                NPT_FAILED(NPT_ParseInteger(input+14, m_Minutes, false))) {
                return NPT_ERROR_INVALID_SYNTAX;
            }
            if (!no_seconds && input[19] == '.') {
                char fraction[10];
                fraction[9] = '\0';
                unsigned int fraction_size = NPT_StringLength(input+20);
                if (fraction_size == 0) return NPT_ERROR_INVALID_SYNTAX;
                for (unsigned int i=0; i<9; i++) {
                    if (i < fraction_size) {
                        fraction[i] = input[20+i];
                    } else {
                        fraction[i] = '0';
                    }
                }
                if (NPT_FAILED(NPT_ParseInteger(fraction, m_NanoSeconds, false))) {
                    return NPT_ERROR_INVALID_SYNTAX;
                }
                input[19] = '\0';
            } else {
                m_NanoSeconds = 0;
            }
            if (!no_seconds) {
                if (NPT_FAILED(NPT_ParseInteger(input+17, m_Seconds, false))) {
                    return NPT_ERROR_INVALID_SYNTAX;
                }
            }
        }
        break;
      }
    
      case FORMAT_RFC_1036: 
      case FORMAT_RFC_1123: {
        if (input_size < 26) return NPT_ERROR_INVALID_SYNTAX;
        // look for the weekday and separtor
        const char* wday = input;
        while (*input && *input != ',') {
            ++input;
            --input_size;
        }
        if (*input == '\0' || *wday == ',') return NPT_ERROR_INVALID_SYNTAX;
        *input++ = '\0';
        --input_size;
        
        // look for the timezone
        char* timezone = input+input_size-1;
        unsigned int timezone_size = 0;
        while (input_size && *timezone != ' ') {
            --timezone;
            ++timezone_size;
            --input_size;
        }
        if (input_size == 0) return NPT_ERROR_INVALID_SYNTAX;
        *timezone++ = '\0';
        
        // check separators
        if (input_size < 20) return NPT_ERROR_INVALID_SYNTAX;
        unsigned int yl = input_size-18;
        if (yl != 2 && yl != 4) return NPT_ERROR_INVALID_SYNTAX;
        char sep;
        int wday_index;
        if (format == FORMAT_RFC_1036) {
            sep = '-';
            wday_index = MatchString(wday, NPT_TIME_DAYS_LONG, 7);
        } else {
            sep = ' ';
            wday_index = MatchString(wday, NPT_TIME_DAYS_SHORT, 7);
        }
        if (input[0]     != ' ' || 
            input[3]     != sep || 
            input[7]     != sep ||
            input[8+yl]  != ' ' ||
            input[11+yl] != ':' ||
            input[14+yl] != ':') {
            return NPT_ERROR_INVALID_SYNTAX;
        }
        input[3] = input[7] = input[8+yl] = input[11+yl] = input[14+yl] = '\0';            

        // parse fields
        m_Month = 1+MatchString(input+4, NPT_TIME_MONTHS, 12);
        if (NPT_FAILED(NPT_ParseInteger(input+1,     m_Day,     false)) ||
            NPT_FAILED(NPT_ParseInteger(input+8,     m_Year,    false)) ||
            NPT_FAILED(NPT_ParseInteger(input+9+yl,  m_Hours,   false)) ||
            NPT_FAILED(NPT_ParseInteger(input+12+yl, m_Minutes, false)) ||
            NPT_FAILED(NPT_ParseInteger(input+15+yl, m_Seconds, false))) {
            return NPT_ERROR_INVALID_SYNTAX;
        }
        
        // adjust short year lengths
        if (yl == 2) m_Year += 1900;
        
        // parse the timezone
        if (NPT_StringsEqual(timezone, "GMT") ||
            NPT_StringsEqual(timezone, "UT")  ||
            NPT_StringsEqual(timezone, "Z")) {
            m_TimeZone = 0;
        } else if (NPT_StringsEqual(timezone, "EDT")) {
            m_TimeZone = -4*60;
        } else if (NPT_StringsEqual(timezone, "EST") ||
                   NPT_StringsEqual(timezone, "CDT")) {
            m_TimeZone = -5*60;
        } else if (NPT_StringsEqual(timezone, "CST") ||
                   NPT_StringsEqual(timezone, "MDT")) {
            m_TimeZone = -6*60;
        } else if (NPT_StringsEqual(timezone, "MST") ||
                   NPT_StringsEqual(timezone, "PDT")) {
            m_TimeZone = -7*60;
        } else if (NPT_StringsEqual(timezone, "PST")) {
            m_TimeZone = -8*60;
        } else if (timezone_size == 1) {
            if (timezone[0] >= 'A' && timezone[0] <= 'I') {
                m_TimeZone = -60*(1+timezone[0]-'A');
            } else if (timezone[0] >= 'K' && timezone[0] <= 'M') {
                m_TimeZone = -60*(timezone[0]-'A');            
            } else if (timezone[0] >= 'N' && timezone[0] <= 'Y') {
                m_TimeZone = 60*(1+timezone[0]-'N');
            } else {
                return NPT_ERROR_INVALID_SYNTAX;
            }
        } else if (timezone_size == 5) {
            int sign;
            if (timezone[0] == '-') {
                sign = -1;
            } else if (timezone[0] == '+') {
                sign = 1;
            } else {
                return NPT_ERROR_INVALID_SYNTAX;
            }
            NPT_UInt32 tz;
            if (NPT_FAILED(NPT_ParseInteger(timezone+1, tz, false))) {
                return NPT_ERROR_INVALID_SYNTAX;
            }
            unsigned int hh = (tz/100);
            unsigned int mm = (tz%100);
            if (hh > 59 || mm > 59) return NPT_ERROR_INVALID_SYNTAX;
            m_TimeZone = sign*(hh*60+mm);
        } else {
            return NPT_ERROR_INVALID_SYNTAX;
        }
        
        // compute the number of days elapsed since 1900
        NPT_UInt32 days = ElapsedDaysSince1900(*this);
        if ((int)((days+1)%7) != wday_index) {
            return NPT_ERROR_INVALID_PARAMETERS;
        }
        
        m_NanoSeconds = 0;

        break;
      }
    
      case FORMAT_ANSI: {
        if (input_size != 24) return NPT_ERROR_INVALID_SYNTAX;

        // check separators
        if (input[3]  != ' ' || 
            input[7]  != ' ' || 
            input[10] != ' ' || 
            input[13] != ':' || 
            input[16] != ':' ||
            input[19] != ' ') {
            return NPT_ERROR_INVALID_SYNTAX;
        }
        input[3] = input[7] = input[10] = input[13] = input[16] = input[19] = '\0';
        if (input[8] == ' ') input[8] = '0';
                
        m_Month = 1+MatchString(input+4, NPT_TIME_MONTHS, 12);
        if (NPT_FAILED(NPT_ParseInteger(input+8,  m_Day,     false)) ||
            NPT_FAILED(NPT_ParseInteger(input+11, m_Hours,   false)) ||
            NPT_FAILED(NPT_ParseInteger(input+14, m_Minutes, false)) ||
            NPT_FAILED(NPT_ParseInteger(input+17, m_Seconds, false)) ||
            NPT_FAILED(NPT_ParseInteger(input+20, m_Year,    false))) {
            return NPT_ERROR_INVALID_SYNTAX;
        }

        // compute the number of days elapsed since 1900
        NPT_UInt32 days = ElapsedDaysSince1900(*this);
        if ((int)((days+1)%7) != MatchString(input, NPT_TIME_DAYS_SHORT, 7)) {
            return NPT_ERROR_INVALID_PARAMETERS;
        }
        
        m_TimeZone    = 0;
        m_NanoSeconds = 0;
        break;
      }
    
      default:
        return NPT_ERROR_INVALID_PARAMETERS;
    }
    
    return CheckDate(*this);
}
Пример #12
0
/*----------------------------------------------------------------------
|   NPT_DateTime::ToString
+---------------------------------------------------------------------*/
NPT_String
NPT_DateTime::ToString(Format format, NPT_Flags flags) const
{
    NPT_String result;
    
    if (NPT_FAILED(CheckDate(*this))) return result;
    
    switch (format) {
        case FORMAT_W3C:
            AppendNumber(result, m_Year, 4);
            result += '-';
            AppendNumber(result, m_Month, 2);
            result += '-';
            AppendNumber(result, m_Day, 2);
            result += 'T';
            AppendNumber(result, m_Hours, 2);
            result += ':';
            AppendNumber(result, m_Minutes, 2);
            result += ':';
            AppendNumber(result, m_Seconds, 2);
            if (flags & FLAG_EMIT_FRACTION) {
                result += '.';
                if (flags & FLAG_EXTENDED_PRECISION) {
                    // nanoseconds precision
                    AppendNumber(result, m_NanoSeconds, 9);
                } else {
                    // only miliseconds precision
                    AppendNumber(result, m_NanoSeconds/1000000, 3);
                }
            }
            if (m_TimeZone) {
                NPT_UInt32 tz;
                if (m_TimeZone > 0) {
                    result += '+';
                    tz = m_TimeZone;
                } else {
                    result += '-';
                    tz = -m_TimeZone;
                }
                AppendNumber(result, tz/60, 2);
                result += ':';
                AppendNumber(result, tz%60, 2);
            } else {
                result += 'Z';
            }
            break;
            
        case FORMAT_ANSI: {
            // compute the number of days elapsed since 1900
            NPT_UInt32 days = ElapsedDaysSince1900(*this);
            
            // format the result
            result.SetLength(24);
            NPT_FormatString(result.UseChars(), result.GetLength()+1, 
                             "%.3s %.3s%3d %.2d:%.2d:%.2d %d",
                             NPT_TIME_DAYS_SHORT[(days+1)%7],
                             NPT_TIME_MONTHS[m_Month-1],
                             m_Day,
                             m_Hours,
                             m_Minutes,
                             m_Seconds,
                             m_Year);
            break;
        }
            
        case FORMAT_RFC_1036:
        case FORMAT_RFC_1123: {
            // compute the number of days elapsed since 1900
            NPT_UInt32 days = ElapsedDaysSince1900(*this);

            if (format == FORMAT_RFC_1036) {
                result += NPT_TIME_DAYS_LONG[(days+1)%7];
                result += ", ";
                AppendNumber(result, m_Day, 2);
                result += '-';
                result += NPT_TIME_MONTHS[m_Month-1];
                result += '-';
                AppendNumber(result, m_Year%100, 2);
            } else {
                result += NPT_TIME_DAYS_SHORT[(days+1)%7];
                result += ", ";
                AppendNumber(result, m_Day, 2);
                result += ' ';
                result += NPT_TIME_MONTHS[m_Month-1];
                result += ' ';
                AppendNumber(result, m_Year, 4);
            }
            result += ' ';
            AppendNumber(result, m_Hours, 2);
            result += ':';
            AppendNumber(result, m_Minutes, 2);
            result += ':';
            AppendNumber(result, m_Seconds, 2);
            if (m_TimeZone) {
                if (m_TimeZone > 0) {
                    result += " +";
                    AppendNumber(result, m_TimeZone/60, 2);
                    AppendNumber(result, m_TimeZone%60, 2);
                } else {
                    result += " -";
                    AppendNumber(result, -m_TimeZone/60, 2);
                    AppendNumber(result, -m_TimeZone%60, 2);
                }
            } else {
                result += " GMT";
            }
            break;
        }
    }

    return result;
}
Пример #13
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	int argc, i;
	UInt16 **argvUnicode;
	UInt8 **argvUTF8;
	int result;
	HANDLE startupCheck;
	UInt16 *moduleFileName, *mutexName;
	DWORD lastError;
	const UInt16 *kMutexBaseName = L"Fsk-startup-check-";

#if USE_TIMEBOMB
	if (!CheckDate())
		return -1;
#endif

	FskMainSetHInstance(hInstance);

	argvUnicode = CommandLineToArgvW(GetCommandLineW(), &argc);
	argvUTF8 = (UInt8 **)calloc(sizeof(UInt16 *), argc);
	for (i= 0; i< argc; i++) {
		int charCount = wcslen(argvUnicode[i]);
		argvUTF8[i] = malloc((charCount + 1) * 3);
		WideCharToMultiByte(CP_UTF8, 0, argvUnicode[i], charCount + 1, argvUTF8[i], (charCount + 1) * 3, NULL, NULL);
	}
	GlobalFree(argvUnicode);

	moduleFileName = (UInt16 *)malloc(sizeof(UInt16) * 520);
	GetModuleFileNameW(0, moduleFileName, 512);
	mutexName = malloc((1 + wcslen(moduleFileName) + wcslen(kMutexBaseName)) * 2);
	wcscpy(mutexName, kMutexBaseName);
	wcscat(mutexName, wcsrchr(moduleFileName, '\\') + 1);
	free(moduleFileName);
	startupCheck = CreateMutexW(0, true, mutexName);
	lastError = GetLastError();
	free(mutexName);
	
   for (i = 0; i < argc; i++){
      if(strcmp(argvUTF8[i],"-new-instance")==0) {
         lastError=0;
         break;
      }
	}
	switch (lastError) {
		case 0:
			result = doMain(kFskMainNetwork | kFskMainServer, argc, argvUTF8);
			break;

		case ERROR_ALREADY_EXISTS: {
			char *fileList;
			UInt32 fileListSize;

			result = 0;
			FskUtilsSetArgs(argc, argvUTF8);
			fileList = FskUtilsGetFileArgs(&fileListSize);
			if (NULL != fileList) {
				char *fileName;
				HANDLE hMapFile;
				char number[64];
				SInt32 val;
				
				val = FskRandom() ^ GetTickCount();
				FskStrNumToStr(val, number, sizeof(number));
				fileName = FskStrDoCat("FskFileOpen-", number);

				hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, fileListSize, fileName);
				if ((NULL != hMapFile) && (INVALID_HANDLE_VALUE != hMapFile)) {
					unsigned char *pBuf = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, fileListSize);
					if (NULL != pBuf) {
						memmove(pBuf, fileList, fileListSize);
						UnmapViewOfFile(pBuf);
						PostMessage(FindWindow("projectf-utils", NULL), RegisterWindowMessage("FskOpenFiles"), 0, val);
					}
					CloseHandle(hMapFile);
				}
				FskMemPtrDispose(fileName);
			}
			}
			break;

		default:
			result = -1;
			break;
	}

	CloseHandle(startupCheck);

	for (i = 0; i < argc; i++)
		free(argvUTF8[i]);
	free(argvUTF8);

	return result;
}
Пример #14
0
CString
XMLRestriction::CheckDatatype(XmlDataType p_type,CString p_value)
{
  CString result;

  // Empty value, nothing to check
  if(p_value.IsEmpty())
  {
    return result;
  }

  try
  {
    // Checking only base datatypes
    // String and CDATA are never checked!
    switch(p_type & XDT_MaskTypes)
    {
      case XDT_AnyURI:            result = CheckAnyURI   (p_value);       break;
      case XDT_Base64Binary:      result = CheckBase64   (p_value);       break;
      case XDT_Boolean:           result = CheckBoolean  (p_value);       break;
      case XDT_Date:              result = CheckDate     (p_value);       break;
      case XDT_Integer:           result = CheckInteger  (p_value);       break;
      case XDT_Decimal:           result = CheckDouble   (p_value,false); break;
      case XDT_Double:            result = CheckDouble   (p_value,true);  break;
      case XDT_DateTime:          result = CheckDateTime (p_value,false); break;
      case XDT_DateTimeStamp:     result = CheckDateTime (p_value,true);  break;
      case XDT_Float:             result = CheckDouble   (p_value,true);  break;
      case XDT_Duration:          result = CheckDuration (p_value);       break;
      case XDT_DayTimeDuration:   result = CheckDaySecond(p_value);       break;
      case XDT_YearMonthDuration: result = CheckYearMonth(p_value);       break;
      case XDT_GregDay:           result = CheckGregDay  (p_value);       break;
      case XDT_GregMonth:         result = CheckGregMonth(p_value);       break;
      case XDT_GregYear:          result = CheckGregYear (p_value);       break;
      case XDT_GregMonthDay:      result = CheckGregMD   (p_value);       break;
      case XDT_GregYearMonth:     result = CheckGregYM   (p_value);       break;
      case XDT_HexBinary:         result = CheckHexBin   (p_value);       break;
      case XDT_Long:              result = CheckLong     (p_value);       break;
      case XDT_Int:               result = CheckLong     (p_value);       break;
      case XDT_Short:             result = CheckShort    (p_value);       break;
      case XDT_NonNegativeInteger:result = CheckNNegInt  (p_value);       break;
      case XDT_PositiveInteger:   result = CheckPosInt   (p_value);       break;
      case XDT_UnsignedLong:      result = CheckUnsLong  (p_value);       break;
      case XDT_UnsignedInt:       result = CheckUnsLong  (p_value);       break;
      case XDT_UnsignedShort:     result = CheckUnsShort (p_value);       break;
      case XDT_UnsignedByte:      result = CheckUnsByte  (p_value);       break;
      case XDT_NonPositiveInteger:result = CheckNonPosInt(p_value);       break;
      case XDT_NegativeInteger:   result = CheckNegInt   (p_value);       break;
      case XDT_Time:              result = CheckTime     (p_value);       break;
      case XDT_Token:             result = CheckToken    (p_value);       break;
      case XDT_NMTOKEN:           result = CheckNMTOKEN  (p_value);       break;
      case XDT_Name:              result = CheckName     (p_value);       break;
      case XDT_ENTITY:            result = CheckName     (p_value);       break;
      case XDT_ID:                result = CheckName     (p_value);       break;
      case XDT_IDREF:             result = CheckName     (p_value);       break;
      case XDT_QName:             result = CheckQName    (p_value);       break;
      case XDT_NMTOKENS:          result = CheckNMTOKENS (p_value);       break;
      case XDT_ENTITIES:          result = CheckNames    (p_value);       break;
      case XDT_IDREFS:            result = CheckNames    (p_value);       break;
      default:                    break;
    }
  }
  catch(StdException& er)
  {
    ReThrowSafeException(er);
    // Primary datatype conversion went wrong
    result = er.GetErrorMessage();
  }
  return result;
}