IUBio

Y2K and SRS

Tim Cutts timc at chiark.greenend.org.uk
Tue Jan 4 08:17:49 EST 2000


In article <84slqi$4j7$1 at mach.vub.ac.be>,
Guy Bottu <gbottu at bigben.vub.ac.be> wrote:
>  case 's':  /* short */
>    if (timeRec->tm_year >= 100)
>      sprintf (timeStr, "%0d/%0d/%0d", timeRec->tm_mon+1,
>                                  timeRec->tm_mday,
>                                  timeRec->tm_year + 1900);
>    else
>      sprintf (timeStr, "%0d/%0d/%0d", timeRec->tm_mon+1,
>                                  timeRec->tm_mday,
>                                  timeRec->tm_year);
>    break;

Guy, thanks for pointing out the bug, but I think the fix is wrong.
Consider the following test code:

#include <stdio.h>
#include <srs.h>

int main(void) {

  SrsEnv();
  LibOpen();

  printf("A date in 1970:\n");
  printf("short: %s\n", TimeToString(100, "short"));
  printf("long:  %s\n", TimeToString(100, "long"));
  printf("date: %s\n", TimeToString(100, "date"));
  printf("\nCurrent time:\n");
  printf("short: %s\n", TimeToString(0, "short"));
  printf("long:  %s\n", TimeToString(0, "long"));
  printf("date: %s\n", TimeToString(0, "date"));

  return 0;
}

With unpatched SRS, this prints:

A date in 1970:
short: 1/1/70
long:  01-Jan-1970 01:01
date: 01-Jan-1970

Current time:
short: 1/4/100
long:  04-Jan-19100 13:05
date: 04-Jan-19100

which demonstrates the bug you pointed out.

Your fix produces this:

A date in 1970:
short: 1/1/70
long:  01-Jan-1970 01:01
date: 01-Jan-1970

Current time:
short: 1/4/2000
long:  04-Jan-2000 13:07
date: 04-Jan-2000

This fixes the bug, but there is now inconsistency in the number of
digits used to display the year in the short form.  This could cause
problems for parsing scripts.  Is it not safer to use four digits
consistently?  My patch (at the end of this message) is based on yours,
but uses four digits at all times.  It produces the following output:

A date in 1970:
short: 1/1/1970
long:  01-Jan-1970 01:01
date: 01-Jan-1970

Current time:
short: 1/4/2000
long:  04-Jan-2000 13:10
date: 04-Jan-2000

Personally, I prefer the consistency, since any scripts which parse getz
output (for example) don't need to be modified to cope with either 2 or
4 digits in the year.

My patch is as follows.  It is a unified diff produced by GNU diff.  If
you have not already applied Guy's fix, you can apply this using GNU
patch as follows: save the patch to a file (say $SRSOU/y2k.patch) and
then do:

cd $SRSSOU
patch < y2k.patch
srsmake

You will need GNU patch for this to work, I think.

Patch follows:

--- tm.c.orig   Tue Jan  4 12:01:08 2000
+++ tm.c        Tue Jan  4 13:05:39 2000
@@ -79,7 +79,7 @@
 
 char *TimeToString (UINT4 userTimeVal, char *opt)
 {
-  static char timeStrBuff[5][30];
+  static char timeStrBuff[10][30];
   static Int4 count;
   static char *month[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul",
                              "Aug","Sep","Oct","Nov","Dec"};
@@ -97,19 +97,19 @@
   case 's':  /* short */
     sprintf (timeStr, "%0d/%0d/%0d", timeRec->tm_mon+1, 
                                  timeRec->tm_mday,
-                                  timeRec->tm_year);
+                                  timeRec->tm_year + 1900);
     break;
   case 'l':  /* long */
-    sprintf (timeStr, "%02d-%s-19%0d %02d:%02d", timeRec->tm_mday, 
+    sprintf (timeStr, "%02d-%s-%0d %02d:%02d", timeRec->tm_mday, 
             month[timeRec->tm_mon], 
-            timeRec->tm_year, 
+            timeRec->tm_year + 1900, 
             timeRec->tm_hour,  
             timeRec->tm_min);
     break;
   case 'd':  /* date */
-    sprintf (timeStr, "%02d-%s-19%0d", timeRec->tm_mday, 
+    sprintf (timeStr, "%02d-%s-%0d", timeRec->tm_mday, 
             month[timeRec->tm_mon], 
-            timeRec->tm_year); 
+            timeRec->tm_year + 1900); 
     break;
   default:
     _ErrExit2 (e__unknownoption, opt);







More information about the Bio-srs mailing list

Send comments to us at biosci-help [At] net.bio.net