Jim Tcl
Check-in [c861d09c19]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:clock scan: Unspecified fields use the current date/time

When scanning a time with unspecified fields, those fields should use the current date/time, not 1 Jan 1900.

Signed-off-by: Steve Bennett <steveb@workware.net.au>

Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c861d09c194cda199f5e5b854c8cca3453aafb1e
User & Date: steveb@workware.net.au 2019-05-20 05:38:53
Original User & Date: steveb@workware.net.au 2019-05-20 05:38:54
Context
2019-05-20
05:38
clock scan: Implement timegm() locally

Don't rely on system timegm(), and use a locally implemented timegm() that doesn't rely on changing TZ in the environment

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: 13abc622e2 user: steveb@workware.net.au tags: trunk

05:38
clock scan: Unspecified fields use the current date/time

When scanning a time with unspecified fields, those fields should use the current date/time, not 1 Jan 1900.

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: c861d09c19 user: steveb@workware.net.au tags: trunk

2018-11-25
22:51
appveyor.yml: update OpenSSL DLL paths check-in: 8d046c71be user: steveb@workware.net.au tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to jim-clock.c.

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
}
#endif

static int clock_cmd_scan(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    char *pt;
    struct tm tm;
    /*time_t now = time(NULL);*/
    /* No default format */
    struct clock_options options = { 0, NULL };

    if (argc % 2 == 0) {
        return -1;
    }

................................................................................
    if (parse_clock_options(interp, argc - 1, argv + 1, &options) == JIM_ERR) {
        return JIM_ERR;
    }
    if (options.format == NULL) {
        return -1;
    }

    /* Set unspecified fields to 0, e.g. HH:MM becomes 00:00 */
    memset(&tm, 0, sizeof(tm));
    /* But this is 1-based */
    tm.tm_mday = 1;

    pt = strptime(Jim_String(argv[0]), options.format, &tm);
    if (pt == 0 || *pt != 0) {
        Jim_SetResultString(interp, "Failed to parse time according to format", -1);
        return JIM_ERR;
    }








|







 







|
<
<
<







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
133
134
135
136
137
138
139
140



141
142
143
144
145
146
147
}
#endif

static int clock_cmd_scan(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    char *pt;
    struct tm tm;
    time_t now = time(NULL);
    /* No default format */
    struct clock_options options = { 0, NULL };

    if (argc % 2 == 0) {
        return -1;
    }

................................................................................
    if (parse_clock_options(interp, argc - 1, argv + 1, &options) == JIM_ERR) {
        return JIM_ERR;
    }
    if (options.format == NULL) {
        return -1;
    }

    localtime_r(&now, &tm);




    pt = strptime(Jim_String(argv[0]), options.format, &tm);
    if (pt == 0 || *pt != 0) {
        Jim_SetResultString(interp, "Failed to parse time according to format", -1);
        return JIM_ERR;
    }