summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2017-05-12 19:58:01 (GMT)
committersebres <sebres@users.sourceforge.net>2017-05-12 19:58:01 (GMT)
commit9f5e6e9b5ff1c04538705d20e601b16c4df821e5 (patch)
treea8c881437bf7f8f1fa4160a0a2ce3e5e458f9628 /generic
parent4213f85e6c843588364c0e410e57e31c6d3ce9d1 (diff)
downloadtcl-9f5e6e9b5ff1c04538705d20e601b16c4df821e5.zip
tcl-9f5e6e9b5ff1c04538705d20e601b16c4df821e5.tar.gz
tcl-9f5e6e9b5ff1c04538705d20e601b16c4df821e5.tar.bz2
Fixed stardate format: be sure positive after decimal point (note: clock-value can be negative - modulo operation in C has the same sign as dividend)
Diffstat (limited to 'generic')
-rw-r--r--generic/tclClockFmt.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c
index 70b3ad7..d3cb339 100644
--- a/generic/tclClockFmt.c
+++ b/generic/tclClockFmt.c
@@ -2489,13 +2489,13 @@ ClockFmtToken_StarDate_Proc(
{
int fractYear;
/* Get day of year, zero based */
- int doy = dateFmt->date.dayOfYear - 1;
+ int v = dateFmt->date.dayOfYear - 1;
/* Convert day of year to a fractional year */
if (IsGregorianLeapYear(&dateFmt->date)) {
- fractYear = 1000 * doy / 366;
+ fractYear = 1000 * v / 366;
} else {
- fractYear = 1000 * doy / 365;
+ fractYear = 1000 * v / 365;
}
/* Put together the StarDate as "Stardate %02d%03d.%1d" */
@@ -2507,8 +2507,10 @@ ClockFmtToken_StarDate_Proc(
dateFmt->output = _itoaw(dateFmt->output,
fractYear, '0', 3);
*dateFmt->output++ = '.';
- dateFmt->output = _itoaw(dateFmt->output,
- dateFmt->date.localSeconds % SECONDS_PER_DAY / ( SECONDS_PER_DAY / 10 ), '0', 1);
+ /* be sure positive after decimal point (note: clock-value can be negative) */
+ v = dateFmt->date.localSeconds % SECONDS_PER_DAY / ( SECONDS_PER_DAY / 10 );
+ if (v < 0) v = 10 + v;
+ dateFmt->output = _itoaw(dateFmt->output, v, '0', 1);
return TCL_OK;
}