3D PLM Enterprise Architecture |
Middleware Abstraction |
Managing TimeCreating and using timestamps and durations |
Use Case |
AbstractThis article shows how to create and use timestamp and duration objects. |
This use case is intended to show you how to create and use timestamps and durations.
[Top]
CAASysTime is a set of use cases of the CAASystem.edu framework that illustrates the System framework capabilities.
[Top]
This use case creates timestamp and duration object instances, check that they are valid, and perform operations on them.
[Top]
To launch CAASysTime, you will need to set up the build time environment, then compile CAASysTime along with its prerequisites, set up the run time environment, and then execute the use case [1].
[Top]
The CAASysTime use case is made of a several classes located in the CAASysTime.m module of the CAASystem.edu framework:
Windows | InstallRootDirectory\CAASystem.edu\CAASysTime.m\ |
Unix | InstallRootDirectory/CAASystem.edu/CAASysTime.m/ |
wherwe InstallRootDirectory
is the directory where the CAA
CD-ROM is installed.
[Top]
The time management capabilities are shown using seven steps:
# |
Step |
---|---|
1 | Create a timestamp |
2 | Retrieve the hours from the timestamp |
3 | Create a duration |
4 | Add two durations |
5 | Retrieve the total number of hours from a duration |
6 | Subtract a duration from a timestamp |
7 | Compare two durations |
[Top]
The CAATime class is dedicated to timestamps.
... int iYear = 1997; int iMonth = 11; int iDay = 20; int iHour = 16; int iMin = 23; int iSec = 15; CATTime MyTime1(iYear, iMonth, iDay, iHour, iMin, iSec); if ( 1 == MyTime1.GetStatus() ) { ... // MyTime1 is a valid instance and can be used ... |
MyTime1
is initialized at Thursday, 20 November 1997
16:23:15
. The GetStatus
method should return 1 if MyTime1
is valid, and 0 otherwise.
[Top]
... int hour = 0; hour = MyTime1.GetHour(); if ( -1 != hour ) cout << "The hour of MyTime1 is: " << hour << endl<<endl; ... |
The hour variable contains the value 16. If the returned value were invalid, -1 would be returned.
[Top]
The CATTimeSpan class is dedicated to durations.
... long iDays = 9; int iHours = 16; int iMins = 45; int iSecs = 54; CATTimeSpan MyTimeSpan1(iDays, iHours, iMins, iSecs); if ( 1 == MyTimeSpan1.GetStatus() ) { ... // MyTimeSpan1 is a valid instance and can be used ... |
MyTimeSpan1
is initialized at 9 days 16:45:54
. The GetStatus
method should return 1 if MyTimeSpan1
is valid, and 0 otherwise.
[Top]
... CATTimeSpan MyTimeSpan2(3, 5, 11, 47 ); if ( 1 == MyTimeSpan2.GetStatus() ) { MyTimeSpan1 += MyTimeSpan2; ... |
A second instance of the CATTimeSpan class is created, whose value is 3
days 5 hours 11 minutes 47 secondes
, and the operator +=
is
used to add it to MyTimeSpan1
. The new value of MyTimeSpan1
is now 12 days 21 hours 57 minutes 41 secondes
.
[Top]
... int span = MyTimeSpan1.GetTotalHours(); ... |
The span
variable contains 309 hours, that is (12 x 24) +
21
.
[Top]
... MyTime1 -= MyTimeSpan1; if ( 1 == MyTime1.GetStatus() ) { ... // MyTime1 is a valid instance and can be used ... |
The duration MyTimeSpan1
is subtracted from the timestamp MyTime1
that new value is Friday, 07 November 1997 18:25:34
.
[Top]
... CATTime MyTime2(2000, 7, 14, 15, 41, 32); if ( 1 == MyTime2.GetStatus() ) { if ( MyTime2 < MyTime1 ) cout << "MyTime2 < MyTime1 is TRUE." << endl<< endl; else cout << "MyTime2 < MyTime1 is FALSE." << endl<< endl; ... |
A new CATTime instance is created with the value Friday, 14 July
2000 15:41:32
, and the second trace is displayed on the console
[Top]
This use case shows how to create and use timestamp and duration objects.
[Top]
[1] | Building and Launching a CAA V5 Use Case |
[Top] |
Version: 1 [Mar 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.