Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
b5af4566
Commit
b5af4566
authored
13 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Use spaceless ISO8601 time format, not sec,usec.
parent
c5b58df7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/common/util.c
+20
-0
20 additions, 0 deletions
src/common/util.c
src/common/util.h
+3
-0
3 additions, 0 deletions
src/common/util.h
src/or/control.c
+3
-3
3 additions, 3 deletions
src/or/control.c
src/test/test_util.c
+20
-1
20 additions, 1 deletion
src/test/test_util.c
with
46 additions
and
4 deletions
src/common/util.c
+
20
−
0
View file @
b5af4566
...
...
@@ -1430,6 +1430,26 @@ format_iso_time(char *buf, time_t t)
strftime
(
buf
,
ISO_TIME_LEN
+
1
,
"%Y-%m-%d %H:%M:%S"
,
tor_gmtime_r
(
&
t
,
&
tm
));
}
/** As format_iso_time, but use the yyyy-mm-ddThh:mm:ss format to avoid
* embedding an internal space. */
void
format_iso_time_nospace
(
char
*
buf
,
time_t
t
)
{
format_iso_time
(
buf
,
t
);
buf
[
10
]
=
'T'
;
}
/** As format_iso_time_nospace, but include microseconds in decimal
* fixed-point format. Requires that buf be at least ISO_TIME_USEC_LEN+1
* bytes long. */
void
format_iso_time_nospace_usec
(
char
*
buf
,
const
struct
timeval
*
tv
)
{
tor_assert
(
tv
);
format_iso_time_nospace
(
buf
,
tv
->
tv_sec
);
tor_snprintf
(
buf
+
ISO_TIME_LEN
,
8
,
".%06d"
,
(
int
)
tv
->
tv_usec
);
}
/** Given an ISO-formatted UTC time value (after the epoch) in <b>cp</b>,
* parse it and store its value in *<b>t</b>. Return 0 on success, -1 on
* failure. Ignore extraneous stuff in <b>cp</b> separated by whitespace from
...
...
This diff is collapsed.
Click to expand it.
src/common/util.h
+
3
−
0
View file @
b5af4566
...
...
@@ -242,8 +242,11 @@ time_t tor_timegm(struct tm *tm);
void
format_rfc1123_time
(
char
*
buf
,
time_t
t
);
int
parse_rfc1123_time
(
const
char
*
buf
,
time_t
*
t
);
#define ISO_TIME_LEN 19
#define ISO_TIME_USEC_LEN (ISO_TIME_LEN+7)
void
format_local_iso_time
(
char
*
buf
,
time_t
t
);
void
format_iso_time
(
char
*
buf
,
time_t
t
);
void
format_iso_time_nospace
(
char
*
buf
,
time_t
t
);
void
format_iso_time_nospace_usec
(
char
*
buf
,
const
struct
timeval
*
tv
);
int
parse_iso_time
(
const
char
*
buf
,
time_t
*
t
);
int
parse_http_time
(
const
char
*
buf
,
struct
tm
*
tm
);
int
format_time_interval
(
char
*
out
,
size_t
out_len
,
long
interval
);
...
...
This diff is collapsed.
Click to expand it.
src/or/control.c
+
3
−
3
View file @
b5af4566
...
...
@@ -1853,10 +1853,10 @@ circuit_describe_status_for_controller(origin_circuit_t *circ)
{
char
*
time_created_arg
=
NULL
;
char
tbuf
[
ISO_TIME_USEC_LEN
+
1
];
format_iso_time_nospace_usec
(
tbuf
,
&
circ
->
_base
.
timestamp_created
);
tor_asprintf
(
&
time_created_arg
,
"TIME_CREATED=%ld,%ld"
,
circ
->
_base
.
timestamp_created
.
tv_sec
,
circ
->
_base
.
timestamp_created
.
tv_usec
);
tor_asprintf
(
&
time_created_arg
,
"TIME_CREATED=%s"
,
tbuf
);
smartlist_add
(
descparts
,
time_created_arg
);
}
...
...
This diff is collapsed.
Click to expand it.
src/test/test_util.c
+
20
−
1
View file @
b5af4566
...
...
@@ -19,9 +19,10 @@ test_util_time(void)
{
struct
timeval
start
,
end
;
struct
tm
a_time
;
char
timestr
[
RFC1123_TIME_LEN
+
1
];
char
timestr
[
128
];
time_t
t_res
;
int
i
;
struct
timeval
tv
;
start
.
tv_sec
=
5
;
start
.
tv_usec
=
5000
;
...
...
@@ -83,6 +84,24 @@ test_util_time(void)
/* We might've timewarped a little. */
tt_int_op
(
tv_udiff
(
&
start
,
&
end
),
>=
,
-
5000
);
/* Now let's check some format_iso_time variants */
tv
.
tv_sec
=
(
time_t
)
1326296338
;
tv
.
tv_usec
=
3060
;
format_iso_time
(
timestr
,
tv
.
tv_sec
);
test_streq
(
"2012-01-11 15:38:58"
,
timestr
);
/* The output of format_local_iso_time will vary by timezone, and setting
our timezone for testing purposes would be a nontrivial flaky pain.
Skip this test for now.
format_local_iso_time(timestr, tv.tv_sec);
test_streq("2012-01-11 10:38:58", timestr);
*/
format_iso_time_nospace
(
timestr
,
tv
.
tv_sec
);
test_streq
(
"2012-01-11T15:38:58"
,
timestr
);
test_eq
(
strlen
(
timestr
),
ISO_TIME_LEN
);
format_iso_time_nospace_usec
(
timestr
,
&
tv
);
test_streq
(
"2012-01-11T15:38:58.003060"
,
timestr
);
test_eq
(
strlen
(
timestr
),
ISO_TIME_USEC_LEN
);
done:
;
}
...
...
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