Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying info structure, yacc rules and flags #17

Merged
merged 2 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 25 additions & 33 deletions generic/tclClock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3796,14 +3796,14 @@ ClockValidDate(
}

/* first year (used later in hath / daysInPriorMonths) */
if ((info->flags & (CLF_YEAR|CLF_ISO8601YEAR)) || yyHaveDate) {
if ((info->flags & (CLF_YEAR|CLF_ISO8601YEAR))) {
if ((info->flags & CLF_ISO8601YEAR)) {
if ( yydate.iso8601Year < dataPtr->validMinYear
|| yydate.iso8601Year > dataPtr->validMaxYear ) {
errMsg = "invalid iso year"; errCode = "iso year"; goto error;
}
}
if ((info->flags & CLF_YEAR) || yyHaveDate) {
if (info->flags & CLF_YEAR) {
if ( yyYear < dataPtr->validMinYear
|| yyYear > dataPtr->validMaxYear ) {
errMsg = "invalid year"; errCode = "year"; goto error;
Expand All @@ -3819,15 +3819,13 @@ ClockValidDate(
}
}
/* and month (used later in hath) */
if ((info->flags & CLF_MONTH) || yyHaveDate) {
info->flags |= CLF_MONTH;
if (info->flags & CLF_MONTH) {
if ( yyMonth < 1 || yyMonth > 12 ) {
errMsg = "invalid month"; errCode = "month"; goto error;
}
}
/* day of month */
if ((info->flags & CLF_DAYOFMONTH) || (yyHaveDate || yyHaveDay)) {
info->flags |= CLF_DAYOFMONTH;
if (info->flags & (CLF_DAYOFMONTH|CLF_DAYOFWEEK)) {
if ( yyDay < 1 || yyDay > 31 ) {
errMsg = "invalid day"; errCode = "day"; goto error;
}
Expand All @@ -3839,7 +3837,7 @@ ClockValidDate(
}
}
}
if ((info->flags & CLF_DAYOFYEAR)) {
if (info->flags & CLF_DAYOFYEAR) {
if ( yydate.dayOfYear < 1
|| yydate.dayOfYear > daysInPriorMonths[IsGregorianLeapYear(&yydate)][12] ) {
errMsg = "invalid day of year"; errCode = "day of year"; goto error;
Expand All @@ -3859,7 +3857,7 @@ ClockValidDate(
}
}

if ((info->flags & CLF_TIME) || yyHaveTime) {
if (info->flags & CLF_TIME) {
/* hour */
if ( yyHour < 0 || yyHour > ((yyMeridian == MER24) ? 23 : 12) ) {
errMsg = "invalid time (hour)"; errCode = "hour"; goto error;
Expand All @@ -3886,7 +3884,7 @@ ClockValidDate(

/* time, regarding the modifications by the time-zone (looks for given time
* in between DST-time hole, so does not exist in this time-zone) */
if (((info->flags & CLF_TIME) || yyHaveTime)) {
if (info->flags & CLF_TIME) {
/*
* we don't need to do the backwards time-conversion (UTC to local) and
* compare results, because the after conversion (local to UTC) we
Expand Down Expand Up @@ -3973,17 +3971,14 @@ ClockFreeScan(
* midnight.
*/

if (yyHaveDate) {
if (info->flags & CLF_YEAR) {
if (yyYear < 100) {
if (yyYear >= dataPtr->yearOfCenturySwitch) {
yyYear -= 100;
}
yyYear += dataPtr->currentYearCentury;
}
yydate.era = CE;
if (yyHaveTime == 0) {
yyHaveTime = -1;
}
info->flags |= CLF_ASSEMBLE_JULIANDAY|CLF_ASSEMBLE_SECONDS;
}

Expand All @@ -3992,7 +3987,7 @@ ClockFreeScan(
* zone indicator of +-hhmm and setup this time zone.
*/

if (yyHaveZone) {
if (info->flags & CLF_ZONE) {
Tcl_Obj *tzObjStor = NULL;
int minEast = -yyTimezone;
int dstFlag = 1 - yyDSTmode;
Expand Down Expand Up @@ -4026,20 +4021,20 @@ ClockFreeScan(
* Assemble date, time, zone into seconds-from-epoch
*/

if (yyHaveTime == -1) {
if ((info->flags & (CLF_TIME|CLF_HAVEDATE)) == CLF_HAVEDATE) {
yySecondOfDay = 0;
info->flags |= CLF_ASSEMBLE_SECONDS;
}
else
if (yyHaveTime) {
if (info->flags & CLF_TIME) {
yySecondOfDay = ToSeconds(yyHour, yyMinutes,
yySeconds, yyMeridian);
info->flags |= CLF_ASSEMBLE_SECONDS;
}
else
if ( (yyHaveDay && !yyHaveDate)
|| yyHaveOrdinalMonth
|| ( yyHaveRel
if ( (info->flags & (CLF_DAYOFWEEK|CLF_HAVEDATE)) == CLF_DAYOFWEEK
|| (info->flags & CLF_ORDINALMONTH)
|| ( (info->flags & CLF_RELCONV)
&& ( yyRelMonth != 0
|| yyRelDay != 0 ) )
) {
Expand Down Expand Up @@ -4092,7 +4087,7 @@ ClockCalcRelTime(
*/
repeat_rel:

if (yyHaveRel) {
if (info->flags & CLF_RELCONV) {

/*
* Relative conversion normally possible in UTC time only, because
Expand Down Expand Up @@ -4164,14 +4159,14 @@ ClockCalcRelTime(
}
}

yyHaveRel = 0;
info->flags &= ~CLF_RELCONV;
}

/*
* Do relative (ordinal) month
*/

if (yyHaveOrdinalMonth) {
if (info->flags & CLF_ORDINALMONTH) {
int monthDiff;

/* if needed extract year, month, etc. again */
Expand All @@ -4197,12 +4192,10 @@ ClockCalcRelTime(
}

/* process it further via relative times */
yyHaveRel++;
yyYear += yyMonthOrdinalIncr;
yyRelMonth += monthDiff;
yyHaveOrdinalMonth = 0;

info->flags |= CLF_ASSEMBLE_JULIANDAY|CLF_ASSEMBLE_SECONDS;
info->flags &= ~CLF_ORDINALMONTH;
info->flags |= CLF_RELCONV|CLF_ASSEMBLE_JULIANDAY|CLF_ASSEMBLE_SECONDS;

goto repeat_rel;
}
Expand All @@ -4211,12 +4204,11 @@ ClockCalcRelTime(
* Do relative weekday
*/

if (yyHaveDay && !yyHaveDate) {
if ((info->flags & (CLF_DAYOFWEEK|CLF_HAVEDATE)) == CLF_DAYOFWEEK) {

/* restore scanned day of week */
if (info->flags & CLF_DAYOFWEEK) {
yyDayOfWeek = prevDayOfWeek;
}
yyDayOfWeek = prevDayOfWeek;

/* if needed assemble julianDay now */
if (info->flags & CLF_ASSEMBLE_JULIANDAY) {
GetJulianDayFromEraYearMonthDay(&yydate, GREGORIAN_CHANGE_DATE);
Expand Down Expand Up @@ -4422,7 +4414,7 @@ ClockAddObjCmd(
* correct date info, because the date may be changed,
* so refresh it now */

if ( yyHaveRel
if ( (info->flags & CLF_RELCONV)
&& ( unitIndex == CLC_ADD_WEEKDAYS
/* some months can be shorter as another */
|| yyRelMonth || yyRelDay
Expand All @@ -4437,7 +4429,7 @@ ClockAddObjCmd(
}

/* process increment by offset + unit */
yyHaveRel++;
info->flags |= CLF_RELCONV;
switch (unitIndex) {
case CLC_ADD_YEARS:
yyRelMonth += offs * 12;
Expand Down Expand Up @@ -4474,7 +4466,7 @@ ClockAddObjCmd(
* Do relative times (if not yet already processed interim):
*/

if (yyHaveRel) {
if (info->flags & CLF_RELCONV) {
if (ClockCalcRelTime(info, &opts) != TCL_OK) {
goto done;
}
Expand Down
Loading