]>
Commit | Line | Data |
---|---|---|
6a5fa4e0 MG |
1 | /* |
2 | * tclXcnvclock.c -- | |
3 | * | |
4 | * Contains the TCL convertclock command. This is in a module seperate | |
5 | * from clock so that it can be excluded, along with the yacc generated code, | |
6 | * since its rather large. | |
7 | *----------------------------------------------------------------------------- | |
8 | * Copyright 1992 Karl Lehenbauer and Mark Diekhans. | |
9 | * | |
10 | * Permission to use, copy, modify, and distribute this software and its | |
11 | * documentation for any purpose and without fee is hereby granted, provided | |
12 | * that the above copyright notice appear in all copies. Karl Lehenbauer and | |
13 | * Mark Diekhans make no representations about the suitability of this | |
14 | * software for any purpose. It is provided "as is" without express or | |
15 | * implied warranty. | |
16 | *----------------------------------------------------------------------------- | |
17 | * $Id: tclXcnvclock.c,v 2.1 1992/11/07 22:23:03 markd Exp $ | |
18 | *----------------------------------------------------------------------------- | |
19 | */ | |
20 | ||
21 | #include "tclxint.h" | |
22 | #include <time.h> | |
23 | ||
24 | \f | |
25 | /* | |
26 | *----------------------------------------------------------------------------- | |
27 | * | |
28 | * Tcl_ConvertclockCmd -- | |
29 | * Implements the TCL convertclock command: | |
30 | * convertclock dateString [GMT|{}] | |
31 | * | |
32 | * Results: | |
33 | * Standard TCL results. | |
34 | * | |
35 | *----------------------------------------------------------------------------- | |
36 | */ | |
37 | int | |
38 | Tcl_ConvertclockCmd (clientData, interp, argc, argv) | |
39 | ClientData clientData; | |
40 | Tcl_Interp *interp; | |
41 | int argc; | |
42 | char **argv; | |
43 | { | |
44 | long clockVal; | |
45 | time_t baseClock; | |
46 | struct tm *timeDataPtr; | |
47 | long zone; | |
48 | ||
49 | if ((argc < 2) || (argc > 4)) { | |
50 | Tcl_AppendResult (interp, tclXWrongArgs, argv [0], | |
51 | " dateString [GMT|{}] [baseclock]", (char *) NULL); | |
52 | return TCL_ERROR; | |
53 | } | |
54 | if (argc == 4) { | |
55 | if (Tcl_GetLong (interp, argv [3], &baseClock) != TCL_OK) | |
56 | return TCL_ERROR; | |
57 | } else | |
58 | time (&baseClock); | |
59 | ||
60 | if ((argc > 2) && (argv [2][0] != '\0')) { | |
61 | if (!STREQU (argv [2], "GMT")) { | |
62 | Tcl_AppendResult (interp, "invalid argument: expected `GMT', ", | |
63 | "got : `", argv [2], "'", (char *) NULL); | |
64 | return TCL_ERROR; | |
65 | } | |
66 | zone = 0; /* Zero minutes from GMT */ | |
67 | } else { | |
68 | timeDataPtr = localtime (&baseClock); | |
69 | /* | |
70 | * Get the minutes east of GMT. | |
71 | */ | |
72 | #ifdef TCL_TM_GMTOFF | |
73 | zone = -(timeDataPtr->tm_gmtoff / 60); | |
74 | #endif | |
75 | #ifdef TCL_TIMEZONE_VAR | |
76 | zone = timezone / 60; | |
77 | #endif | |
78 | #if !defined(TCL_TM_GMTOFF) && !defined(TCL_TIMEZONE_VAR) | |
79 | zone = timeDataPtr->tm_tzadj / 60; | |
80 | #endif | |
81 | } | |
82 | ||
83 | clockVal = Tcl_GetDate (argv [1], baseClock, zone); | |
84 | if (clockVal == -1) { | |
85 | Tcl_AppendResult (interp, "Unable to convert date-time string \"", | |
86 | argv [1], "\"", (char *) NULL); | |
87 | return TCL_ERROR; | |
88 | } | |
89 | sprintf (interp->result, "%ld", clockVal); | |
90 | return TCL_OK; | |
91 | } | |
92 |