Diff
Not logged in

Differences From Artifact [ab6b04c6ec]:

To Artifact [9f36afc498]:


133
134
135
136
137
138
139



140
141
142
143
144
145
146
			    register DateInfo *info,
			    Tcl_Obj *strObj, ClockFmtScnCmdArgs *opts);
static int		ClockCalcRelTime(
			    register DateInfo *info, ClockFmtScnCmdArgs *opts);
static int		ClockAddObjCmd(
			    ClientData clientData, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);



static struct tm *	ThreadSafeLocalTime(const time_t *);
static size_t		TzsetIfNecessary(void);
static void		ClockDeleteCmdProc(ClientData);

/*
 * Structure containing description of "native" clock commands to create.
 */







>
>
>







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
			    register DateInfo *info,
			    Tcl_Obj *strObj, ClockFmtScnCmdArgs *opts);
static int		ClockCalcRelTime(
			    register DateInfo *info, ClockFmtScnCmdArgs *opts);
static int		ClockAddObjCmd(
			    ClientData clientData, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		ClockValidDate(
			    ClientData, register DateInfo *,
			    register ClockFmtScnCmdArgs *);
static struct tm *	ThreadSafeLocalTime(const time_t *);
static size_t		TzsetIfNecessary(void);
static void		ClockDeleteCmdProc(ClientData);

/*
 * Structure containing description of "native" clock commands to create.
 */
3655
3656
3657
3658
3659
3660
3661







3662
3663
3664
3665
3666
3667
3668
	if (yydate.julianDay > 5373484) {
	    Tcl_SetObjResult(opts->interp, Tcl_NewStringObj(
		"requested date too large to represent", -1));
	    Tcl_SetErrorCode(opts->interp, "CLOCK", "dateTooLarge", NULL);
	    return TCL_ERROR;
	}
    }








    /* Local seconds to UTC (stored in yydate.seconds) */

    if (info->flags & (CLF_ASSEMBLE_SECONDS|CLF_ASSEMBLE_JULIANDAY)) {
	yydate.localSeconds =
	    -210866803200L
	    + ( SECONDS_PER_DAY * (Tcl_WideInt)yydate.julianDay )







>
>
>
>
>
>
>







3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
	if (yydate.julianDay > 5373484) {
	    Tcl_SetObjResult(opts->interp, Tcl_NewStringObj(
		"requested date too large to represent", -1));
	    Tcl_SetErrorCode(opts->interp, "CLOCK", "dateTooLarge", NULL);
	    return TCL_ERROR;
	}
    }

    /* Apply validation rules, if expected */
    if ( (opts->flags & CLF_VALIDATE) ) {
	if (ClockValidDate(clientData, info, opts) != TCL_OK) {
	    return TCL_ERROR;
	}
    }

    /* Local seconds to UTC (stored in yydate.seconds) */

    if (info->flags & (CLF_ASSEMBLE_SECONDS|CLF_ASSEMBLE_JULIANDAY)) {
	yydate.localSeconds =
	    -210866803200L
	    + ( SECONDS_PER_DAY * (Tcl_WideInt)yydate.julianDay )
3678
3679
3680
3681
3682
3683
3684





























































3685
3686
3687
3688
3689
3690
3691

    /* Increment UTC seconds with relative time */

    yydate.seconds += yyRelSeconds;

    return TCL_OK;
}






























































/*----------------------------------------------------------------------
 *
 * ClockFreeScan --
 *
 *	Used by ClockScanObjCmd for free scanning without format.
 *







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762

    /* Increment UTC seconds with relative time */

    yydate.seconds += yyRelSeconds;

    return TCL_OK;
}

/*----------------------------------------------------------------------
 *
 * ClockValidDate --
 *
 *	Validate date info structure for wrong data (e. g. out of ranges).
 *
 * Results:
 *	Returns a standard Tcl result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
ClockValidDate(
    ClientData clientData,	/* Client data containing literal pool */
    register DateInfo  *info,	/* Clock scan info structure */
    register
    ClockFmtScnCmdArgs *opts)	/* Format, locale, timezone and base */
{
    const char *errMsg;

    //printf("yyMonth %d, yyDay %d, yyHour %d, yyMinutes %d, yySeconds %d\n", yyMonth, yyDay, yyHour, yyMinutes, yySeconds);
    
    /* first month (used later in hath) */
    if ( yyMonth < 1 || yyMonth > 12 ) {
	errMsg = "invalid month"; goto error;
    }
    /* day of month */
    if ( yyDay < 1 || yyDay > 31 ) {
	errMsg = "invalid day"; goto error;
    } else {
	const int *h = hath[IsGregorianLeapYear(&yydate)];
	if ( yyDay > h[yyMonth-1] ) {
	    errMsg = "invalid day"; goto error;
	}
    }
    /* hour */
    if ( yyHour < 0 || yyHour > ((yyMeridian == MER24) ? 24 : 12) ) {
	errMsg = "invalid time (hour)"; goto error;
    }
    /* minutes */
    if ( yyMinutes < 0 || yyMinutes > 59 ) {
	errMsg = "invalid time (minutes)"; goto error;
    }
    /* oldscan could return secondOfDay (parsedTime) -1 by invalid time (ex.: 25:00:00) */
    if (yySeconds <= -1) {
	errMsg = "invalid time"; goto error;
    }

    return TCL_OK;

  error:
    Tcl_SetObjResult(opts->interp,
	Tcl_ObjPrintf("unable to convert input string: %s", errMsg));
    Tcl_SetErrorCode(opts->interp, "CLOCK", "invInpStr", NULL);
    return TCL_ERROR;
}

/*----------------------------------------------------------------------
 *
 * ClockFreeScan --
 *
 *	Used by ClockScanObjCmd for free scanning without format.
 *