Tcl Source Code

Check-in [7be9cada94]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

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

Overview
Comment:scan: all JDN/JD are signed, so allow parse negative Julian days
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | clock-astronomical-jdn
Files: files | file ages | folders
SHA3-256: 7be9cada9474b040ced17bb9b5661302bcd5627c857fb50ed905aaa397db61a0
User & Date: sebres 2019-03-13 00:24:44
Context
2019-03-13
00:33
integrate branch clock-astronomical-jdn: merge pull request #16 from sebres/astronomical-jdn (https:... check-in: 39a21f437a user: sebres tags: sebres-8-6-clock-speedup-cr2
00:24
scan: all JDN/JD are signed, so allow parse negative Julian days Closed-Leaf check-in: 7be9cada94 user: sebres tags: clock-astronomical-jdn
00:24
format: add support of new JDN-tokens (calendar JD `%EJ`, astronomical JD `%Ej`) with time fraction.... check-in: 2194d065f7 user: sebres tags: clock-astronomical-jdn
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to generic/tclClockFmt.c.

  1592   1592       Tcl_WideInt intJD; int fractJD = 0, fractJDDiv = 1;
  1593   1593   
  1594   1594       DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
  1595   1595   
  1596   1596       end = yyInput + maxLen;
  1597   1597   
  1598   1598       /* currently positive astronomic dates only */
  1599         -    if (*p == '+') { p++; };
         1599  +    if (*p == '+' || *p == '-') { p++; };
  1600   1600       s = p;
  1601   1601       while (p < end && isdigit(UCHAR(*p))) {
  1602   1602   	p++;
  1603   1603       }
  1604         -    if ( _str2wideInt(&intJD, s, p, 1) != TCL_OK) {
         1604  +    if ( _str2wideInt(&intJD, s, p, (*yyInput != '-' ? 1 : -1)) != TCL_OK) {
  1605   1605   	return TCL_RETURN;
  1606   1606       };
  1607   1607       yyInput = p;
  1608   1608       if (p >= end || *p++ != '.') { /* allow pure integer JDN */
  1609   1609   	/* by astronomical JD the seconds of day offs is 12 hours */
  1610   1610   	if (tok->map->offs) {
  1611   1611   	    goto done;
................................................................................
  1640   1640       yydate.julianDay = intJD;
  1641   1641   
  1642   1642       yydate.seconds =
  1643   1643   	-210866803200L
  1644   1644   	+ ( SECONDS_PER_DAY * intJD )
  1645   1645   	+ ( fractJD );
  1646   1646   
  1647         -    info->flags |= CLF_POSIXSEC | CLF_SIGNED;
         1647  +    info->flags |= CLF_POSIXSEC;
  1648   1648   
  1649   1649       return TCL_OK;
  1650   1650   }
  1651   1651   
  1652   1652   static int
  1653   1653   ClockScnToken_TimeZone_Proc(ClockFmtScnCmdArgs *opts,
  1654   1654       DateInfo *info, ClockScanToken *tok)
................................................................................
  1834   1834       /* %S */
  1835   1835       {CTOKT_INT, CLF_TIME, 0, 1, 2, TclOffset(DateInfo, date.secondOfMin),
  1836   1836   	NULL},
  1837   1837       /* %p %P */
  1838   1838       {CTOKT_PARSER, 0, 0, 0, 0xffff, 0,
  1839   1839   	ClockScnToken_amPmInd_Proc, NULL},
  1840   1840       /* %J */
  1841         -    {CTOKT_WIDE, CLF_JULIANDAY, 0, 1, 0xffff, TclOffset(DateInfo, date.julianDay),
         1841  +    {CTOKT_WIDE, CLF_JULIANDAY | CLF_SIGNED, 0, 1, 0xffff, TclOffset(DateInfo, date.julianDay),
  1842   1842   	NULL},
  1843   1843       /* %j */
  1844   1844       {CTOKT_INT, CLF_DAYOFYEAR, 0, 1, 3, TclOffset(DateInfo, date.dayOfYear),
  1845   1845   	NULL},
  1846   1846       /* %C */
  1847   1847       {CTOKT_INT, CLF_CENTURY|CLF_ISO8601CENTURY, 0, 1, 2, TclOffset(DateInfo, dateCentury),
  1848   1848   	NULL},
................................................................................
  1883   1883   static const char *ScnETokenMapIndex =
  1884   1884       "EJjys";
  1885   1885   static ClockScanTokenMap ScnETokenMap[] = {
  1886   1886       /* %EE */
  1887   1887       {CTOKT_PARSER, 0, 0, 0, 0xffff, TclOffset(DateInfo, date.year),
  1888   1888   	ClockScnToken_LocaleERA_Proc, (void *)MCLIT_LOCALE_NUMERALS},
  1889   1889       /* %EJ */
  1890         -    {CTOKT_PARSER, CLF_JULIANDAY, 0, 1, 0xffff, 0, /* calendar JDN starts at midnight */
         1890  +    {CTOKT_PARSER, CLF_JULIANDAY | CLF_SIGNED, 0, 1, 0xffff, 0, /* calendar JDN starts at midnight */
  1891   1891   	ClockScnToken_JDN_Proc, NULL},
  1892   1892       /* %Ej */
  1893         -    {CTOKT_PARSER, CLF_JULIANDAY, 0, 1, 0xffff, (SECONDS_PER_DAY/2), /* astro JDN starts at noon */
         1893  +    {CTOKT_PARSER, CLF_JULIANDAY | CLF_SIGNED, 0, 1, 0xffff, (SECONDS_PER_DAY/2), /* astro JDN starts at noon */
  1894   1894   	ClockScnToken_JDN_Proc, NULL},
  1895   1895       /* %Ey */
  1896   1896       {CTOKT_PARSER, 0, 0, 0, 0xffff, 0, /* currently no capture, parse only token */
  1897   1897   	ClockScnToken_LocaleListMatcher_Proc, (void *)MCLIT_LOCALE_NUMERALS},
  1898   1898       /* %Es */
  1899   1899       {CTOKT_WIDE, CLF_LOCALSEC | CLF_SIGNED, 0, 1, 0xffff, TclOffset(DateInfo, date.localSeconds),
  1900   1900   	NULL},

Changes to tests/clock.test.

 18970  18970   	[clock scan {0 2440589} -format {%s %Ej} -gmt true]
 18971  18971   } {86400 0 43200 129600}
 18972  18972   
 18973  18973   test clock-7.19 {Astronomical JDN/JD, two values} {
 18974  18974       clock scan {2440588 2440589} -format {%Ej %Ej} -gmt true
 18975  18975   } 129600
 18976  18976   
        18977  +test clock-7.20 {all JDN/JD are signed (and extended accept floats)} {
        18978  +    set res {}
        18979  +    foreach i {%J %EJ %Ej} {
        18980  +	lappend res [clock scan "-1" -format $i -gmt 1]
        18981  +    }
        18982  +    foreach i {%EJ %Ej} {
        18983  +	lappend res [clock scan "-1.5" -format $i -gmt 1]
        18984  +    }
        18985  +    set res
        18986  +} {-210866889600 -210866889600 -210866846400 -210866846400 -210866803200}
        18987  +
 18977  18988   # BEGIN testcases8
 18978  18989   
 18979  18990   # Test parsing of ccyymmdd
 18980  18991   
 18981  18992   test clock-8.1 {parse ccyymmdd} {
 18982  18993       clock scan {1970 Jan 02} -format {%C%y %b %d} -locale en_US_roman -gmt 1
 18983  18994   } 86400