datetime.cpp

来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 654 行 · 第 1/2 页

CPP
654
字号
    TTime theStart(*startPtr);
    TTime end(*endPtr);
    TTimeIntervalHours hours;
    end.HoursFrom(theStart,hours);
    aOplAPI.Push(TInt32(hours.Int()));
    }


void CDateTimeOpx::DTMinutesDiff(OplAPI& aOplAPI)
    {                                                           // Check ptr s
    TDateTime* endPtr=(TDateTime*)aOplAPI.PopInt32();
    TDateTime* startPtr=(TDateTime*)aOplAPI.PopInt32();
    CheckPointerL(endPtr);
    CheckPointerL(startPtr);
    TTime theStart(*startPtr);
    TTime end(*endPtr);
    TTimeIntervalMinutes minutes;
    end.MinutesFrom(theStart,minutes);
    aOplAPI.Push(TInt32(minutes.Int()));
    }


void CDateTimeOpx::DTSecsDiff(OplAPI& aOplAPI)
    {                                                           // Check ptr s
    TDateTime* endPtr=(TDateTime*)aOplAPI.PopInt32();
    TDateTime* startPtr=(TDateTime*)aOplAPI.PopInt32();
    CheckPointerL(endPtr);
    CheckPointerL(startPtr);
    TTime theStart(*startPtr);
    TTime end(*endPtr);
    TTimeIntervalSeconds seconds;
    end.SecondsFrom(theStart,seconds);
    aOplAPI.Push(TInt32(seconds.Int()));
    }


void CDateTimeOpx::DTMicrosDiff(OplAPI& aOplAPI)
    {                                                           // Check ptr s
    TDateTime* endPtr=(TDateTime*)aOplAPI.PopInt32();
    TDateTime* startPtr=(TDateTime*)aOplAPI.PopInt32();
    CheckPointerL(endPtr);
    CheckPointerL(startPtr);

    TTime theStart(*startPtr);
    TTime end(*endPtr);
    TInt64 microSeconds(end.MicroSecondsFrom(theStart).Int64());
    if(microSeconds<KMinTInt32 || microSeconds>KMaxTInt32)
       User::Leave(KOplErrOverflow);                // error if in any mode already
    aOplAPI.Push(TInt32(microSeconds.GetTInt()));
    }


void CDateTimeOpx::DTWeekNoInYear(OplAPI& aOplAPI)
    {                                                           // Check ptr s
    TFirstWeekRule rule=(TFirstWeekRule)aOplAPI.PopInt32();
    TDateTime* startPtr=(TDateTime*)aOplAPI.PopInt32();
    TDateTime* Now=(TDateTime*)aOplAPI.PopInt32();
    CheckPointerL(Now);
    CheckPointerL(startPtr);
    TTime theStart(*startPtr);
    TTime now(*Now);
    switch(rule)
	    {
	    case EFirstWeek:
        case EFirstFourDayWeek:
        case EFirstFullWeek:
     		break;				
        default:
             User::Leave(KOplErrInvalidArgs);                // error if in any mode already
             break;
	         } 

    aOplAPI.Push(TInt32(now.WeekNoInYear(theStart,rule)));
    }


void CDateTimeOpx::DTDayNoInYear (OplAPI& aOplAPI)
    {                                                           // Check ptr s
    TDateTime* startPtr=(TDateTime*)aOplAPI.PopInt32();
    TDateTime* Now=(TDateTime*)aOplAPI.PopInt32();
    CheckPointerL(Now);
    CheckPointerL(startPtr);
    TTime theStart(*startPtr);
    TTime now(*Now);

    aOplAPI.Push(TInt32(now.DayNoInYear(theStart)));
    }

                
void CDateTimeOpx::DTDayNoInWeek(OplAPI& aOplAPI)
    {                                                           // Check ptr s
    TDateTime* startPtr=(TDateTime*)aOplAPI.PopInt32();
    CheckPointerL(startPtr);
    TTime now(*startPtr);
    aOplAPI.Push(TInt32(now.DayNoInWeek()+1));
    }


void CDateTimeOpx::DTDaysInMonth(OplAPI& aOplAPI)
    {                                                           // Check ptr s
    TDateTime* startPtr=(TDateTime*)aOplAPI.PopInt32();
    CheckPointerL(startPtr);
    TTime now(*startPtr);
    aOplAPI.Push(TInt32(now.DaysInMonth()));
    }

// Filetime setters and getters are located here, and not System,
// because these use an entry in the TDateTime array.
    
void CDateTimeOpx::DTFileTime(OplAPI& aOplAPI)
    {
    TDateTime* pDate=(TDateTime*)aOplAPI.PopInt32();
	CheckPointerL(pDate);
    TPtrC file=aOplAPI.PopString();
    RFs& fs=aOplAPI.DbManager()->FsSession();
    TTime tim(*pDate);
    fs.Modified(file,tim);
    *pDate=tim.DateTime();
    aOplAPI.Push(TReal64(0.0));
    }

void CDateTimeOpx::DTSetFileTime(OplAPI& aOplAPI)
    {
    TDateTime* pDate=(TDateTime*)aOplAPI.PopInt32();
	CheckPointerL(pDate);
    TPtrC file=aOplAPI.PopString();
    RFs& fs=aOplAPI.DbManager()->FsSession();
    TTime tim(*pDate);
    fs.SetModified(file,tim);
    aOplAPI.Push(TReal64(0.0));
    }

void CDateTimeOpx::DTIsLeapYear(OplAPI& aOplAPI)
	{
	TInt year=aOplAPI.PopInt32();
	aOplAPI.Push(TInt32(Time::IsLeapYear(year) ? -1 : 0));
	}


CTlsDataOPXTime::CTlsDataOPXTime(OplAPI& aOplAPI) : COpxBase(aOplAPI)
    {
    }


CTlsDataOPXTime* CTlsDataOPXTime::NewL(OplAPI& aOplAPI)
    {
    CTlsDataOPXTime* This=new(ELeave) CTlsDataOPXTime(aOplAPI);
    CleanupStack::PushL(This);
    This->ConstructL();
    CleanupStack::Pop();
    return This;
    }


void CTlsDataOPXTime::ConstructL()
    {
    iDateHandle= new(ELeave) CDateTimeOpx;
    } 


CTlsDataOPXTime::~CTlsDataOPXTime()
    {
    delete iDateHandle;
	Dll::FreeTls();
    }


//
// OPX loading interface
//

void CTlsDataOPXTime::RunL(TInt aProcNum)
// Run a language extension procedure
	{
	switch (aProcNum)
		{
	case EDTNewDateTime:
		 iDateHandle->DTNewDateTime(iOplAPI);
		break;
	case EDTDeleteDateTime:
		 iDateHandle->DTDeleteDateTime(iOplAPI);
		break;

	case EDTYear:
		 iDateHandle->DTYear(iOplAPI);
		break;
	case EDTMonth:
		 iDateHandle->DTMonth(iOplAPI);
		break;
	case EDTDay:
		 iDateHandle->DTDay(iOplAPI);
		break;
	case EDTHour:
		 iDateHandle->DTHour(iOplAPI);
		break;
	case EDTMinute:
		 iDateHandle->DTMinute(iOplAPI);
		break;
	case EDTSecond:
		 iDateHandle->DTSecond(iOplAPI);
		break;
	case EDTMicro:
		 iDateHandle->DTMicro(iOplAPI);
		break;

	case EDTSetYearL:
		 iDateHandle->DTSetYearL(iOplAPI);
		break;
	case EDTSetMonthL:
		 iDateHandle->DTSetMonthL(iOplAPI);
		break;
	case EDTSetDayL:
		 iDateHandle->DTSetDayL(iOplAPI);
		break;
	case EDTSetHourL:
		 iDateHandle->DTSetHourL(iOplAPI);
		break;
	case EDTSetMinuteL:
		 iDateHandle->DTSetMinuteL(iOplAPI);
		break;
	case EDTSetSecondL:
		 iDateHandle->DTSetSecondL(iOplAPI);
		break;
	case EDTSetMicroL:
		iDateHandle->DTSetMicroL(iOplAPI);
		break;

    case EDTSetHomeTime:
		iDateHandle->DTSetHomeTime(iOplAPI);
		break; 
	case EDTNow: 
		iDateHandle->DTNow(iOplAPI);
		break; 

    case EDTDateTimeDiff:
		iDateHandle->DTDateTimeDiff(iOplAPI);
		break; 
    case EDTYearsDiff:
		iDateHandle->DTYearsDiff(iOplAPI); 
		break; 
    case EDTMonthsDiff: 
		iDateHandle->DTMonthsDiff(iOplAPI);
		break; 
    case EDTDaysDiff:
		iDateHandle->DTDaysDiff(iOplAPI); 
		break; 
    case EDTHoursDiff:
		iDateHandle->DTHoursDiff(iOplAPI);
		break; 
    case EDTMinutesDiff:
		iDateHandle->DTMinutesDiff(iOplAPI); 
		break; 
    case EDTSecsDiff:
		iDateHandle->DTSecsDiff(iOplAPI);
		break; 
    case EDTMicrosDiff: 
		iDateHandle->DTMicrosDiff(iOplAPI); 
		break; 

    case EDTWeekNoInYear:
		iDateHandle->DTWeekNoInYear(iOplAPI);
		break; 
    case EDTDayNoInYear:
		iDateHandle->DTDayNoInYear(iOplAPI); 
		break; 
    case EDTDayNoInWeek:
		iDateHandle->DTDayNoInWeek(iOplAPI);
		break; 
    case EDTDaysInMonth: 
		iDateHandle->DTDaysInMonth(iOplAPI);
		break; 
	case EDTFileTime:
		iDateHandle->DTFileTime(iOplAPI);
		break;
	case EDTSetFileTime:
		iDateHandle->DTSetFileTime(iOplAPI);
		break;
	case EDTIsLeapYear:
		iDateHandle->DTIsLeapYear(iOplAPI);
		break;
	default:
		User::Leave(KOplErrOpxProcNotFound);
		}
	}


TBool CTlsDataOPXTime::CheckVersion(TInt aVersion)
// To check whether the opx is a compatible version
// *** Change as required ***
	{
	if ((aVersion & 0xff00)>(KOpxDateVersion & 0xff00))	// major version must be <= OPX's version
		return EFalse; // bad version
	else
		return ETrue; // ok
	}


EXPORT_C COpxBase* NewOpxL(OplAPI& aOplAPI)
// Creates a COpxBase instance as required by the OPL runtime
// This object is to be stored in the OPX's TLS as shown below
	{
	CTlsDataOPXTime* tls=((CTlsDataOPXTime*)Dll::Tls());
	if (tls==NULL)
		{
        tls=CTlsDataOPXTime::NewL(aOplAPI);
	    Dll::SetTls(tls);
        }
    return (COpxBase *)tls;
	}


EXPORT_C TUint Version()
	{
	return KOpxDateVersion;
	}


GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
//
// DLL entry point
//
	{
	return(KErrNone);
	}

/* endPtr of $Workfile:   datetime.cpp  $ */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?