diff --git a/mozilla/calendar/libxpical/oeDateTimeImpl.cpp b/mozilla/calendar/libxpical/oeDateTimeImpl.cpp index d54cd83d2f6..83d43e92a02 100644 --- a/mozilla/calendar/libxpical/oeDateTimeImpl.cpp +++ b/mozilla/calendar/libxpical/oeDateTimeImpl.cpp @@ -44,6 +44,7 @@ #include "stdlib.h" icaltimetype ConvertFromPrtime( PRTime indate ); +PRTime ConvertToPrtime ( icaltimetype indate ); /* Implementation file */ NS_IMPL_ISUPPORTS1(oeDateTimeImpl, oeIDateTime) @@ -145,8 +146,7 @@ NS_IMETHODIMP oeDateTimeImpl::SetMinute(PRInt16 newval) NS_IMETHODIMP oeDateTimeImpl::GetTime(PRTime *retval) { - PRTime result = icaltime_as_timet( m_datetime ); - *retval = result*1000; + *retval = ConvertToPrtime( m_datetime ); return NS_OK; } diff --git a/mozilla/calendar/libxpical/oeICalEventImpl.cpp b/mozilla/calendar/libxpical/oeICalEventImpl.cpp index 21067b67328..06ed592a7f7 100644 --- a/mozilla/calendar/libxpical/oeICalEventImpl.cpp +++ b/mozilla/calendar/libxpical/oeICalEventImpl.cpp @@ -59,18 +59,42 @@ char *EmptyReturn() { icaltimetype ConvertFromPrtime( PRTime indate ) { icaltimetype outdate; - time_t seconds = indate /1000; - struct tm t = *(localtime(&seconds)); + PRExplodedTime ext; + PRInt64 indateinusec, usecpermsec; + LL_I2L( usecpermsec, PR_USEC_PER_MSEC ); + LL_MUL( indateinusec, indate, usecpermsec ); + PR_ExplodeTime( indateinusec, PR_LocalTimeParameters, &ext); + + outdate.year = ext.tm_year; + outdate.month = ext.tm_month + 1; + outdate.day = ext.tm_mday; + outdate.hour = ext.tm_hour; + outdate.minute = ext.tm_min; + outdate.second = ext.tm_sec; - outdate.year = t.tm_year+ 1900; - outdate.month = t.tm_mon + 1; - outdate.day = t.tm_mday; - outdate.hour = t.tm_hour; - outdate.minute = t.tm_min; - outdate.second = t.tm_sec; return outdate; } +PRTime ConvertToPrtime ( icaltimetype indate ) { + PRExplodedTime ext; + + PR_ExplodeTime( PR_Now(), PR_LocalTimeParameters, &ext); + + ext.tm_year = indate.year; + ext.tm_month = indate.month - 1; + ext.tm_mday = indate.day; + ext.tm_hour = indate.hour; + ext.tm_min = indate.minute; + ext.tm_sec = indate.second; + ext.tm_usec = 0; + + PRTime result = PR_ImplodeTime( &ext ); + PRInt64 usecpermsec; + LL_I2L( usecpermsec, PR_USEC_PER_MSEC ); + LL_DIV( result, result, usecpermsec ); + return result; +} + ////////////////////////////////////////////////// // ICalEvent Factory @@ -614,8 +638,7 @@ NS_IMETHODIMP oeICalEventImpl::GetLastAlarmAck(PRTime *aRetVal) #ifdef ICAL_DEBUG_ALL printf( "GetLastAlarmAck()\n" ); #endif - *aRetVal = icaltime_as_timet( m_lastalarmack ); - *aRetVal /= 1000; + *aRetVal = ConvertToPrtime( m_lastalarmack ); return NS_OK; } NS_IMETHODIMP oeICalEventImpl::SetLastAlarmAck(PRTime aNewVal) @@ -637,7 +660,13 @@ NS_IMETHODIMP oeICalEventImpl::GetNextRecurrence( PRTime begin, PRTime *retval, if( !m_recur ) { PRTime start; m_start->GetTime( &start ); - if( (start/1000) > (begin/1000) ) { + + PRInt64 startinsec,begininsec,msecpersec; + LL_I2L( msecpersec, PR_MSEC_PER_SEC ); + LL_DIV( startinsec, start, msecpersec ); + LL_DIV( begininsec, begin, msecpersec ); + + if( LL_CMP( startinsec, > , begininsec ) ) { *retval = start; *isvalid = true; } @@ -671,9 +700,8 @@ NS_IMETHODIMP oeICalEventImpl::GetNextRecurrence( PRTime begin, PRTime *retval, printf( "Wrong day in month\n" ); continue; } - PRTime nextinms = icaltime_as_timet( next ); - nextinms *= 1000; - if( (nextinms > begin) && !IsExcepted( nextinms ) ) { + PRTime nextinms = ConvertToPrtime( next ); + if( LL_CMP(nextinms, > ,begin) && !IsExcepted( nextinms ) ) { // printf( "Result: %d-%d-%d %d:%d\n" , next.year, next.month, next.day, next.hour, next.minute ); *retval = nextinms; *isvalid = true; @@ -689,8 +717,7 @@ NS_IMETHODIMP oeICalEventImpl::GetNextRecurrence( PRTime begin, PRTime *retval, icaltimetype oeICalEventImpl::GetNextRecurrence( icaltimetype begin ) { icaltimetype result = icaltime_null_time(); - PRTime begininms = icaltime_as_timet( begin ); - begininms *= 1000; + PRTime begininms = ConvertToPrtime( begin ); PRTime resultinms; PRBool isvalid; GetNextRecurrence( begininms ,&resultinms, &isvalid ); @@ -729,11 +756,11 @@ icaltimetype oeICalEventImpl::GetNextAlarmTime( icaltimetype begin ) { icaltimetype oeICalEventImpl::CalculateAlarmTime( icaltimetype date ) { icaltimetype result = date; if( strcasecmp( m_alarmunits, "days" ) == 0 ) - icaltime_adjust( &result, -m_alarmlength, 0, 0, 0 ); + icaltime_adjust( &result, -(signed long)m_alarmlength, 0, 0, 0 ); else if( strcasecmp( m_alarmunits, "hours" ) == 0 ) - icaltime_adjust( &result, 0, -m_alarmlength, 0, 0 ); + icaltime_adjust( &result, 0, -(signed long)m_alarmlength, 0, 0 ); else - icaltime_adjust( &result, 0, 0, -m_alarmlength, 0 ); + icaltime_adjust( &result, 0, 0, -(signed long)m_alarmlength, 0 ); return result; } @@ -837,8 +864,7 @@ NS_IMETHODIMP oeICalEventImpl::AddException( PRTime exdate ) tmpexdate.hour = 0; tmpexdate.minute = 0; tmpexdate.second = 0; - exdate = icaltime_as_timet( tmpexdate ); - exdate *= 1000; + exdate = ConvertToPrtime( tmpexdate ); m_exceptiondates.push_back( exdate ); return NS_OK; } @@ -869,8 +895,7 @@ bool oeICalEventImpl::IsExcepted( PRTime date ) { tmpexdate.hour = 0; tmpexdate.minute = 0; tmpexdate.second = 0; - date = icaltime_as_timet( tmpexdate ); - date *= 1000; + date = ConvertToPrtime( tmpexdate ); bool result = false; for( int i=0; iGetNextRecurrence( checkdateloop, &checkdateloop, &isvalid ); - while( isvalid && (checkdateloopGetId( &tmpid ); eventEnum->AddEventId( tmpid ); @@ -1018,8 +1013,7 @@ oeICalImpl::GetNextNEvents( PRTime datems, PRInt32 maxcount, nsISimpleEnumerator checkdate.minute = 0; checkdate.second = 0; icaltime_adjust( &checkdate, 0, 0, 0, -1 ); - PRTime checkdateinms = icaltime_as_timet( checkdate ); - checkdateinms *= 1000; + PRTime checkdateinms = ConvertToPrtime( checkdate ); EventList *tmplistptr = &m_eventlist; int i=0,count=0; @@ -1077,8 +1071,11 @@ void oeICalImpl::SetupAlarmManager() { printf( "oeICalImpl::SetupAlarmManager()\n" ); #endif - PRTime todayinms = time( nsnull ); - todayinms *= 1000; + PRTime todayinms = PR_Now(); + PRInt64 usecpermsec; + LL_I2L( usecpermsec, PR_USEC_PER_MSEC ); + LL_DIV( todayinms, todayinms, usecpermsec ); + icaltimetype now = ConvertFromPrtime( todayinms ); // printf( "NOW IS: %s\n", icaltime_as_ctime( now ) );