Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Lukas Weber
load_leveller
Commits
390ffb98
Commit
390ffb98
authored
Apr 09, 2019
by
Lukas Weber
Browse files
duration format
parent
d9b15899
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/runner.cpp
View file @
390ffb98
...
...
@@ -22,37 +22,37 @@ enum {
};
// parses the duration '[[hours:]minutes:]seconds' into seconds
// replace as soon as there is an alternative
static
double
parse_duration
(
std
::
string
str
)
{
int
i1
=
-
1
,
i2
=
-
1
,
i3
=
-
1
;
size_t
idx
;
try
{
i1
=
std
::
stoi
(
str
,
&
idx
,
10
);
int
i1
=
std
::
stoi
(
str
,
&
idx
,
10
);
if
(
idx
==
str
.
size
())
{
return
i1
;
}
else
if
(
str
[
idx
]
==
':'
)
{
std
::
string
str1
=
str
.
substr
(
idx
);
i2
=
std
::
stoi
(
str1
,
&
idx
,
10
);
std
::
string
str1
=
str
.
substr
(
idx
+
1
);
int
i2
=
std
::
stoi
(
str1
,
&
idx
,
10
);
if
(
idx
==
str
.
size
())
{
if
(
idx
==
str
1
.
size
())
{
return
60
*
i1
+
i2
;
}
else
if
(
str
[
idx
]
==
':'
)
{
std
::
string
str2
=
str
.
substr
(
idx
);
i3
=
std
::
stoi
(
str2
,
&
idx
,
10
);
if
(
idx
!=
str
.
size
())
{
throw
std
::
exception
{
};
std
::
string
str2
=
str
1
.
substr
(
idx
+
1
);
int
i3
=
std
::
stoi
(
str2
,
&
idx
,
10
);
if
(
idx
!=
str
2
.
size
())
{
throw
std
::
runtime_error
{
"minutes"
};
}
return
24
*
60
*
i1
+
60
*
i2
+
i3
;
}
else
{
throw
std
::
exception
{
};
throw
std
::
runtime_error
{
"hours"
};
}
}
else
{
throw
std
::
exception
{
};
throw
std
::
runtime_error
{
"seconds"
};
}
}
catch
(
std
::
exception
e
)
{
throw
std
::
runtime_error
{
fmt
::
format
(
"'{}' does not fit time format [[hours:]minutes:]seconds"
,
str
)};
fmt
::
format
(
"'{}' does not fit time format [[hours:]minutes:]seconds
: {}
"
,
str
,
e
.
what
()
)};
}
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment