예제 #1
0
// localtime as returned here is seconds elapsed since 1/1/1601 rather
// than that C library standard of seconds elapsed wince 1/1/1970. However
// the following implementation of localtime and gmtime handle this correctly.
time_t tinyclr_time ( time_t * timer )
{
    INT64 tim = Time_GetLocalTime();
    time_t localtime;

    if(s_TimeUntil1900 == 0)
    {
        SYSTEMTIME st;

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

        st.wMonth = 1;
        st.wDay  = 1;
        st.wYear = 1900;

        s_TimeUntil1900 = Time_FromSystemTime(&st);
    }

    tim -= s_TimeUntil1900;

    tim = (tim / MF_TIME_TO_SECONDS); // convert from 100nano to seconds

    localtime = (time_t)tim;

    if (timer != NULL) *timer = localtime;
    
    return localtime;
}
void CLR_RT_HeapBlock_Timer::AdjustNextFixedExpire( const SYSTEMTIME& systemTime, bool fNext )
{
    NATIVE_PROFILE_CLR_CORE();
    SYSTEMTIME st = systemTime;
    CLR_INT64  baseTime;
    CLR_INT64  add;

    CLR_RT_ExecutionEngine::InvalidateTimerCache();

    switch(m_flags & CLR_RT_HeapBlock_Timer::c_AnyChange)
    {
    case CLR_RT_HeapBlock_Timer::c_SecondChange: add = TIME_CONVERSION__ONESECOND * (CLR_INT64)TIME_CONVERSION__TO_SECONDS;                                               break;
    case CLR_RT_HeapBlock_Timer::c_MinuteChange: add = TIME_CONVERSION__ONEMINUTE * (CLR_INT64)TIME_CONVERSION__TO_SECONDS; st.wSecond = 0;                               break;
    case CLR_RT_HeapBlock_Timer::c_HourChange  : add = TIME_CONVERSION__ONEHOUR   * (CLR_INT64)TIME_CONVERSION__TO_SECONDS; st.wSecond = 0; st.wMinute = 0;               break;
    case CLR_RT_HeapBlock_Timer::c_DayChange   : add = TIME_CONVERSION__ONEDAY    * (CLR_INT64)TIME_CONVERSION__TO_SECONDS; st.wSecond = 0; st.wMinute = 0; st.wHour = 0; break;

    default                                    : return;
    }

    st.wMilliseconds = 0;
    baseTime = Time_FromSystemTime( &st );

    m_timeExpire     = fNext ? baseTime + add : baseTime;
    m_timeFrequency  = add;
    m_flags         |= CLR_RT_HeapBlock_Timer::c_Recurring;
}
예제 #3
0
void Test_Time()
{
    LCD_Clear();
    lcd_printf("Testing SSL Time functions...\n");
	SYSTEMTIME systime;

	INT64 getlocaltime = Time_GetLocalTime();
	TINYCLR_SSL_PRINTF("Time_GetLocalTime(): %d\n", getlocaltime);
	Time_ToSystemTime(getlocaltime,&systime);
	INT64 fromsystemtime = Time_FromSystemTime(&systime);
	TINYCLR_SSL_PRINTF("Time_FromSystemTime: %d\n", fromsystemtime);

	time_t time = TINYCLR_SSL_TIME(NULL);
	TINYCLR_SSL_PRINTF("TINYCLR_SSL_TIME in ms: %d\n", (INT64)time);
	struct tm *local =	TINYCLR_SSL_LOCALTIME(&time);
	TINYCLR_SSL_PRINTF("Local Time: %s %2d %02d:%02d:%02d %d\n",
		mon[local->tm_mon-1],
		local->tm_mday,
		local->tm_hour,
		local->tm_min,
		local->tm_sec,
		local->tm_year);
	
	struct tm *gmtime =	TINYCLR_SSL_GMTIME(&time);
	TINYCLR_SSL_PRINTF("GM Time: %s %2d %02d:%02d:%02d %d\n",
		mon[gmtime->tm_mon],
		gmtime->tm_mday,
		gmtime->tm_hour,
		gmtime->tm_min,
		gmtime->tm_sec,
		gmtime->tm_year);
}
// Compress function always creates local time.
void Library_corlib_native_System_DateTime::Compress( CLR_RT_StackFrame& stack, const SYSTEMTIME& st )
{
    NATIVE_PROFILE_CLR_CORE();
    CLR_INT64* val = GetValuePtr( stack );

    if(val) 
    {
        *val = Time_FromSystemTime( &st );
    }
}
예제 #5
0
time_t tinyclr_mktime ( struct tm * timeptr )
{
    SYSTEMTIME systime;
    systime.wHour = timeptr->tm_hour;
    systime.wDay = timeptr->tm_mday;
    systime.wMinute = timeptr->tm_min;
    systime.wMonth = timeptr->tm_mon + 1;  // SYSTEMTIME structure is one based and struct tm is zero based
    systime.wSecond = timeptr->tm_sec;
    systime.wDayOfWeek = timeptr->tm_wday;
    systime.wYear = timeptr->tm_year + 1900; // struct tm records years since 1900
    time_t localtime = (time_t)((Time_FromSystemTime(&systime) - s_TimeUntil1900) / MF_TIME_TO_SECONDS); //convert from 100nano to seconds
    return localtime;
}
HRESULT Library_corlib_native_System_DateTime::get_Today___STATIC__SystemDateTime( CLR_RT_StackFrame& stack )
{
    NATIVE_PROFILE_CLR_CORE();
    TINYCLR_HEADER();

    CLR_INT64* pRes = NewObject( stack );

    {
        SYSTEMTIME st; 
        Time_ToSystemTime( Time_GetLocalTime(), &st );

        st.wHour         = 0;
        st.wMinute       = 0;
        st.wSecond       = 0;
        st.wMilliseconds = 0;

        *pRes = Time_FromSystemTime( &st );
    }

    TINYCLR_NOCLEANUP_NOLABEL();
}
HRESULT Library_spot_net_security_native_Microsoft_SPOT_Net_Security_SslNative::ParseCertificate___STATIC__VOID__SZARRAY_U1__STRING__BYREF_STRING__BYREF_STRING__BYREF_mscorlibSystemDateTime__BYREF_mscorlibSystemDateTime( CLR_RT_StackFrame& stack )
{
    NATIVE_PROFILE_CLR_NETWORK();
    TINYCLR_HEADER();

    CLR_RT_HeapBlock_Array* arrData    = stack.Arg0().DereferenceArray(); 
    CLR_UINT8*              certBytes;
    CLR_RT_HeapBlock        hbIssuer;
    CLR_RT_HeapBlock        hbSubject;
    CLR_RT_ProtectFromGC    gc1( hbIssuer  );
    CLR_RT_ProtectFromGC    gc2( hbSubject );
    X509CertData            cert;
    CLR_INT64*              val;
    CLR_INT64               tzOffset;
    SYSTEMTIME              st;
    INT32                   standardBias;
    CLR_RT_HeapBlock*       hbPwd     = stack.Arg1().DereferenceString();
    LPCSTR                  szPwd;


    FAULT_ON_NULL_ARG(hbPwd);

    szPwd = hbPwd->StringText();

    CLR_RT_Memory::ZeroFill( &cert, sizeof(cert) );

    FAULT_ON_NULL(arrData);

    certBytes = arrData->GetFirstElement();

    if(!SSL_ParseCertificate( (const char*)certBytes, arrData->m_numOfElements, szPwd, &cert )) TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);

    TINYCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbIssuer, cert.Issuer ));
    TINYCLR_CHECK_HRESULT(hbIssuer.StoreToReference( stack.Arg2(), 0 ));

    TINYCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbSubject, cert.Subject ));
    TINYCLR_CHECK_HRESULT(hbSubject.StoreToReference( stack.Arg3(), 0 ));

    st.wYear         = cert.EffectiveDate.year;
    st.wMonth        = cert.EffectiveDate.month;
    st.wDay          = cert.EffectiveDate.day;
    st.wHour         = cert.EffectiveDate.hour;
    st.wMinute       = cert.EffectiveDate.minute;
    st.wSecond       = cert.EffectiveDate.second;
    st.wMilliseconds = cert.EffectiveDate.msec;

    standardBias     = Time_GetTimeZoneOffset();
    standardBias    *= TIME_CONVERSION__ONEMINUTE;

    val = Library_corlib_native_System_DateTime::GetValuePtr( stack.Arg4() );
    *val = Time_FromSystemTime( &st );

    tzOffset = cert.EffectiveDate.tzOffset;

    // adjust for timezone differences
    if(standardBias != tzOffset)
    {
        *val += tzOffset - standardBias; 
    }

    st.wYear         = cert.ExpirationDate.year;
    st.wMonth        = cert.ExpirationDate.month;
    st.wDay          = cert.ExpirationDate.day;
    st.wHour         = cert.ExpirationDate.hour;
    st.wMinute       = cert.ExpirationDate.minute;
    st.wSecond       = cert.ExpirationDate.second;
    st.wMilliseconds = cert.ExpirationDate.msec;
    
    val = Library_corlib_native_System_DateTime::GetValuePtr( stack.ArgN( 5 ) );
    *val = Time_FromSystemTime( &st );

    tzOffset = cert.ExpirationDate.tzOffset;
    
    if(standardBias != tzOffset)
    {
       *val += tzOffset - standardBias; 
    }

    TINYCLR_NOCLEANUP();
}