Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
Main
Synchronet
Commits
7e628349
Commit
7e628349
authored
17 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
This is a useful little program that I use for testing time_t operations.
parent
3063c440
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/unixtime.c
+114
-0
114 additions, 0 deletions
src/xpdev/unixtime.c
with
114 additions
and
0 deletions
src/xpdev/unixtime.c
0 → 100644
+
114
−
0
View file @
7e628349
/* $Id$ */
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
#include
<string.h>
#ifndef __unix__
#include
<dos.h>
#endif
#include
<ctype.h>
#define USE_SNPRINTF
/* we don't need safe_snprintf for this project */
#include
"genwrap.h"
#define TIMEZONE _timezone
#define DAYLIGHT _daylight
/****************************************************************************/
/* Converts a date string in format MM/DD/YY into unix time format */
/****************************************************************************/
time_t
dstrtounix
(
char
*
str
)
{
char
*
p
;
struct
tm
t
;
memset
(
&
t
,
0
,
sizeof
(
t
));
t
.
tm_year
=
((
str
[
6
]
&
0xf
)
*
10
)
+
(
str
[
7
]
&
0xf
);
if
(
t
.
tm_year
<
70
)
t
.
tm_year
+=
100
;
t
.
tm_mon
=
((
str
[
0
]
&
0xf
)
*
10
)
+
(
str
[
1
]
&
0xf
);
if
(
t
.
tm_mon
)
t
.
tm_mon
--
;
t
.
tm_mday
=
((
str
[
3
]
&
0xf
)
*
10
)
+
(
str
[
4
]
&
0xf
);
p
=
strchr
(
str
,
' '
);
if
(
p
)
{
t
.
tm_hour
=
atoi
(
++
p
);
p
=
strchr
(
p
,
':'
);
if
(
p
)
{
t
.
tm_min
=
atoi
(
++
p
);
p
=
strchr
(
p
,
':'
);
if
(
p
)
t
.
tm_sec
=
atoi
(
++
p
);
}
}
return
(
mktime
(
&
t
));
}
time_t
checktime
()
{
struct
tm
tm
;
memset
(
&
tm
,
0
,
sizeof
(
tm
));
tm
.
tm_year
=
94
;
tm
.
tm_mday
=
1
;
return
(
mktime
(
&
tm
)
^
0x2D24BD00L
);
}
int
main
(
int
argc
,
char
**
argv
)
{
char
str
[
256
];
char
revision
[
16
];
time_t
t
;
struct
tm
*
tm
;
int
argn
=
1
;
printf
(
"
\n
"
);
DESCRIBE_COMPILER
(
str
);
sscanf
(
"$Revision$"
,
"%*s %s"
,
revision
);
printf
(
"Rev %s Built "
__DATE__
" "
__TIME__
" with %s
\n\n
"
,
revision
,
str
);
#if 0
if((t=checktime())!=0L) {
printf("Time problem (%08lX)\n",t);
exit(1); }
#endif
if
(
argc
<
2
)
printf
(
"usage: unixtime [-z] <MM/DD/YY HH:MM:SS || time_t>
\n\n
"
);
if
(
argc
>
1
&&
stricmp
(
argv
[
1
],
"-z"
)
==
0
)
{
/* zulu/GMT/UTC timezone */
printf
(
"Setting timezone to Zulu/GMT/UTC
\n\n
"
);
putenv
(
"TZ=UTC0"
);
tzset
();
argn
++
;
}
printf
(
"timezone=%d
\n
"
,
TIMEZONE
);
printf
(
"daylight=%d
\n
"
,
DAYLIGHT
);
printf
(
"
\n
"
);
if
(
argc
>
argn
&&
argv
[
argn
][
2
]
==
'/'
)
{
sprintf
(
str
,
"%s %s"
,
argv
[
argn
],
argc
>
argn
+
1
?
argv
[
argn
+
1
]
:
""
);
if
((
t
=
dstrtounix
(
str
))
==-
1
)
{
printf
(
"dstrtounix error
\n
"
);
return
-
1
;
}
printf
(
"Using specified date and time: "
);
}
else
if
(
argc
>
argn
)
{
printf
(
"Using specified time_t value: "
);
t
=
strtoul
(
argv
[
argn
],
NULL
,
0
);
}
else
{
printf
(
"Using current time_t value: "
);
t
=
time
(
NULL
);
}
printf
(
"%ld (%08lX)
\n
"
,
t
,
t
);
if
((
tm
=
localtime
(
&
t
))
==
NULL
)
printf
(
"localtime() failure
\n
"
);
else
printf
(
"%-8s %.24s
\n
"
,
"local"
,
asctime
(
tm
));
if
((
tm
=
gmtime
(
&
t
))
==
NULL
)
printf
(
"gmtime() failure
\n
"
);
else
printf
(
"%-8s %.24s
\n
"
,
"GMT"
,
asctime
(
tm
));
return
(
0
);
}
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