Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Y
YAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Control System
Libraries
YAT
Commits
4869fed9
Commit
4869fed9
authored
Mar 4, 2024
by
Stéphane Poirier
Browse files
Options
Downloads
Patches
Plain Diff
[Time] add_sec(), operator+=(), operator-=() now return *this and other minor changes
parent
11271048
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/yat/time/Time.h
+41
-21
41 additions, 21 deletions
include/yat/time/Time.h
with
41 additions
and
21 deletions
include/yat/time/Time.h
+
41
−
21
View file @
4869fed9
...
...
@@ -106,38 +106,38 @@ inline int64 int64FromHLPair(long lHigh, unsigned long ulLow)
#ifndef MS_SEC
//! Number of milliseconds per second.
#define MS_SEC 1000L
#define MS_SEC 1000
U
L
#endif
//! Number of microseconds per second.
#define MICROSEC_PER_SEC 1000000L
#define MICROSEC_PER_SEC 1000000
U
L
//! Number of nanoseconds per second.
#define NANOSEC_PER_SEC 1000000000LL
#define NANOSEC_PER_SEC 1000000000
U
LL
//! Number of nanoseconds per millisecond.
#define NANOSEC_PER_MILLISEC 1000000L
#define NANOSEC_PER_MILLISEC 1000000
U
L
//! Number of nanoseconds per millisecond.
#define NANOSEC_PER_MICROSEC 1000
#define NANOSEC_PER_MICROSEC 1000
U
//! Number of microseconds per day - High part.
#define MICROSEC_PER_DAY_H 20L
#define MICROSEC_PER_DAY_H 20
U
L
//! Number of microseconds per day - Low part.
#define MICROSEC_PER_DAY_L 500654080UL
//! Number of microseconds per day.
#define MICROSEC_PER_DAY int64FromHLPair(MICROSEC_PER_DAY_H, MICROSEC_PER_DAY_L) // microseconds per day
//! max number of seconds for a duration
#define DURATION_MAX_SECS 4294967295
L
L
#define DURATION_MAX_SECS 4294967295
U
L
//! max number of milliseconds for a duration
#define DURATION_MAX_MILLIS 4294967295000LL
#define DURATION_MAX_MILLIS 4294967295000
U
LL
//! max number of microseconds for a duration
#define DURATION_MAX_MICROS 4294967295000000LL
#define DURATION_MAX_MICROS 4294967295000000
U
LL
//! max number of nanoseconds for a duration
#define DURATION_MAX_NANOS 4294967295000000000LL
#define DURATION_MAX_NANOS 4294967295000000000
U
LL
#ifndef MS_OVERFLOW
//! \brief Number of milliseconds indicating an int64 capacity overflow.
...
...
@@ -487,19 +487,39 @@ public:
//! \brief Adds seconds to the date.
//! \param dSec Number of seconds to add.
void
add_sec
(
double
dSec
)
{
m_llTime
+=
int64
(
dSec
*
1e6
);
}
Time
&
add_sec
(
double
dSec
)
{
m_llTime
+=
int64
(
dSec
*
1e6
);
return
*
this
;
}
//! \brief Adds a duration to the date.
//! \param d The duration to add
Time
&
add
(
const
class
Duration
&
d
);
//! \brief Substract a duration to the date.
//! \param d The duration to substract
Time
&
sub
(
const
class
Duration
&
d
);
//! \brief operator+=.
//!
//! Adds seconds to the date.
//! \param dSec Number of seconds to add.
void
operator
+=
(
double
dSec
)
{
add_sec
(
dSec
);
}
Time
&
operator
+=
(
double
dSec
)
{
return
add_sec
(
dSec
);
}
//! \brief operator-=.
//!
//! Subtracts seconds to the date.
//! \param dSec Number of seconds to subtract.
void
operator
-=
(
double
dSec
)
{
add_sec
(
-
dSec
);
}
Time
&
operator
-=
(
double
dSec
)
{
return
add_sec
(
-
dSec
);
}
//! \brief operator+=.
//!
//! Adds a duration to the date.
//! \param d the duration to add
Time
&
operator
+=
(
const
class
Duration
&
d
);
//! \brief operator-=.
//!
//! Substract a duration to the date.
//! \param d the duration to add
Time
&
operator
-=
(
const
class
Duration
&
d
);
//@}
...
...
@@ -876,9 +896,9 @@ public:
Duration
(
int64
microsecs
)
:
m_nanos
(
llabs
(
microsecs
)
*
1000LL
)
{
}
//! c-tor
//! \param seconds duration in seconds with
micr
oseconds precision
//! \param seconds duration in seconds with
nan
oseconds precision
//! a negative value will be converted to positive one
Duration
(
double
seconds
)
:
m_nanos
(
int64
(
fabs
(
seconds
)
*
NANOSEC_PER_SEC
)
)
{
}
Duration
(
double
seconds
)
:
m_nanos
(
u
int64
(
fabs
(
seconds
)
*
NANOSEC_PER_SEC
)
)
{
}
//! Distance between t1 and t2, always positive
Duration
(
const
Time
&
t1
,
const
Time
&
t2
);
...
...
@@ -902,7 +922,7 @@ public:
template
<
class
T
>
T
&
as
()
{
throw
yat
::
Exception
(
"BAD_CAST"
,
"Can't convert duration to the requested type"
,
throw
Exception
(
"BAD_CAST"
,
"Can't convert duration to the requested type"
,
"Duration::get<T>"
);
}
...
...
@@ -975,7 +995,7 @@ public:
if
(
fabs
(
secs
)
<=
DURATION_MAX_SECS
)
Duration
::
raw_value
(
uint64
(
fabs
(
secs
)
*
NANOSEC_PER_SEC
+
0.5
));
else
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"Seconds::Seconds"
);
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"
yat::
Seconds::Seconds"
);
}
//! return the number of seconds as a floating point value
...
...
@@ -997,7 +1017,7 @@ public:
if
(
ms
<=
DURATION_MAX_MILLIS
)
Duration
::
raw_value
(
ms
*
NANOSEC_PER_MILLISEC
);
else
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"Millisecs::Millisecs"
);
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"
yat::
Millisecs::Millisecs"
);
}
uint64
get
()
const
{
return
uint64
(
double
(
raw_value
())
/
NANOSEC_PER_MILLISEC
+
0.5
);
}
...
...
@@ -1018,7 +1038,7 @@ public:
if
(
us
<=
DURATION_MAX_MICROS
)
Duration
::
raw_value
(
us
*
NANOSEC_PER_MICROSEC
);
else
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"Microsecs::Microsecs"
);
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"
yat::
Microsecs::Microsecs"
);
}
uint64
get
()
const
{
return
uint64
(
double
(
raw_value
())
/
NANOSEC_PER_MICROSEC
+
0.5
);
}
...
...
@@ -1039,7 +1059,7 @@ public:
if
(
ns
<=
DURATION_MAX_NANOS
)
Duration
::
raw_value
(
ns
);
else
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"Nanosecs::Nanosecs"
);
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"
yat::
Nanosecs::Nanosecs"
);
}
uint64
get
()
const
{
return
raw_value
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment