07469d2d0d55667942c3d64ebbc9d473eee97d53
tdreszer
  Thu Feb 10 14:56:58 2011 -0800
Moved date routines into common, and made expired restriction dates dimmer in hgTrackUi
diff --git src/hg/lib/hui.c src/hg/lib/hui.c
index 38e094e..1848fb8 100644
--- src/hg/lib/hui.c
+++ src/hg/lib/hui.c
@@ -3662,101 +3662,30 @@
     int ix;
     for(ix=0;ix<membership->count;ix++)
         {
         int iIx = stringArrayIx(membership->membership[ix], hierarchy->membership, hierarchy->count);
         if(iIx >= 0)
             {
             indent = hierarchy->indents[iIx];
             break;  // Only one
             }
         }
     }
 for(;indent>0;indent--)
     puts ("&nbsp;&nbsp;&nbsp;");
 }
 
-static int daysOfMonth(struct tm *tp)
-{
-int days=0;
-switch(tp->tm_mon)
-    {
-    case 3:
-    case 5:
-    case 8:
-    case 10:    days = 30;   break;
-    case 1:     days = 28;
-                if( (tp->tm_year % 4) == 0
-                && ((tp->tm_year % 20) != 0 || (tp->tm_year % 100) == 0) )
-                    days = 29;
-                break;
-    default:    days = 31;   break;
-    }
-return days;
-}
-
-static void dateAdd(struct tm *tp,int addYears,int addMonths,int addDays)
-/* Add years,months,days to a date */
-{
-tp->tm_mday  += addDays;
-tp->tm_mon   += addMonths;
-tp->tm_year  += addYears;
-int dom=28;
-while( (tp->tm_mon >11  || tp->tm_mon <0)
-    || (tp->tm_mday>dom || tp->tm_mday<1) )
-    {
-    if(tp->tm_mon>11)   // First month: tm.tm_mon is 0-11 range
-        {
-        tp->tm_year += (tp->tm_mon / 12);
-        tp->tm_mon  = (tp->tm_mon % 12);
-        }
-    else if(tp->tm_mon<0)
-        {
-        tp->tm_year += (tp->tm_mon / 12) - 1;
-        tp->tm_mon  =  (tp->tm_mon % 12) + 12;
-        }
-    else
-        {
-        dom = daysOfMonth(tp);
-        if(tp->tm_mday>dom)
-            {
-            tp->tm_mday -= dom;
-            tp->tm_mon  += 1;
-            dom = daysOfMonth(tp);
-            }
-        else if(tp->tm_mday < 1)
-            {
-            tp->tm_mon  -= 1;
-            dom = daysOfMonth(tp);
-            tp->tm_mday += dom;
-            }
-        }
-    }
-}
-static char *dateAddToAndFormat(char *date,char *format,int addYears,int addMonths,int addDays)
-/* Add years,months,days to a formatted date and returns the new date as a string on the stack
-*  format is a strptime/strftime format: %F = yyyy-mm-dd */
-{
-char *newDate = needMem(12);
-struct tm tp;
-if(strptime (date,format, &tp))
-    {
-    dateAdd(&tp,addYears,addMonths,addDays); // tp.tm_year only contains years since 1900
-    strftime(newDate,12,format,&tp);
-    }
-return newDate;  // newDate is never freed!
-}
-
 // FIXME FIXME Should be able to use membersForAll struct to set default sort order from subGroups
 // FIXME FIXME This should be done in hgTrackDb at load time and should change tag values to ensure js still works
 boolean tdbAddPrioritiesFromCart(struct cart *cart, struct trackDb *tdbList)
 /* Updates the tdb->priority from cart for all tracks in list and their
  * descendents. */
 {
 char htmlIdentifier[128];
 struct trackDb *tdb;
 boolean cartPriorities = FALSE;
 for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
     {
     safef(htmlIdentifier, sizeof(htmlIdentifier), "%s.priority", tdb->track);
     char *cartHas = cartOptionalString(cart,htmlIdentifier);
     if(cartHas != NULL)
 	{
@@ -3840,50 +3769,50 @@
 
 char *encodeRestrictionDateDisplay(char *db,struct trackDb *trackDb)
 /* Create a string for ENCODE restriction date of this track
    if return is not null, then free it after use */
 {
 if (!trackDb)
     return NULL;
 
 boolean addMonths = FALSE;
 char *date = NULL;
 
 if(metadataForTable(db,trackDb,NULL) != NULL)
     {
     addMonths = FALSE;
     date = cloneString((char *)metadataFindValue(trackDb,"dateUnrestricted"));
-    if(date == NULL)
+    if(date == NULL)  // TODO: The logic to calculate date based upon dateSubmitted should be removed.  However, I don't think we can do it until the mdb is used for all hg18 composites.
         {
         date = cloneString((char *)metadataFindValue(trackDb,"dateSubmitted"));
         addMonths = TRUE;
         }
     }
 if(date == NULL)
     {
     date = trackDbSetting(trackDb, "dateSubmitted");
     if(date)
         {
         addMonths = TRUE;
         date = cloneString(date); // all returns should be freeable memory
         }
     }
 if (date != NULL)
     {
     date = strSwapChar(date, ' ', 0);   // Truncate time
     if(addMonths)
-        date = dateAddToAndFormat(date, "%F", 0, 9, 0);
+        date = dateAddTo(date, "%F", 0, 9, 0);
     }
 return date;
 }
 
 static void cfgLinkToDependentCfgs(struct cart *cart, struct trackDb *tdb,char *prefix)
 /* Link composite or view level controls to all associateled lower level controls */
 {
 if (!cartVarExists(cart, "ajax") && tdbIsComposite(tdb))
 #ifdef SUBTRACK_CFG_POPUP
     printf("<script type='text/javascript'>registerViewOnchangeAction('%s')</script>\n",prefix);
 #else///ifndef SUBTRACK_CFG_POPUP
     printf("<script type='text/javascript'>compositeCfgRegisterOnchangeAction(\"%s\")</script>\n",prefix);
 #endif///ndef SUBTRACK_CFG_POPUP
 }
 
@@ -4235,33 +4164,41 @@
         safef(htmlIdentifier,sizeof(htmlIdentifier),"%s.childShowCfg",subtrack->track);
         boolean open = cartUsualBoolean(cart, htmlIdentifier,FALSE);
         MAKE_CFG_SUBTRACK_DIV(subtrack->track,htmlIdentifier,open);
         safef(htmlIdentifier,sizeof(htmlIdentifier),"%s",subtrack->track);
         cfgByCfgType(cType,db,cart,subtrack,htmlIdentifier,"Subtrack",TRUE);
         printf("</DIV>");
         }
 #endif///ndef SUBTRACK_CFG_POPUP
 
     // A schema link for each track
     printf("</td>\n<TD>&nbsp;");
     makeSchemaLink(db,subtrack,"schema");
     printf("&nbsp;");
 
     // Do we have a restricted until date?
+    if (restrictions)
+        {
     char *dateDisplay = encodeRestrictionDateDisplay(db,subtrack);
     if (dateDisplay)
+            {
+            if (dateIsOld(dateDisplay,"%F"))
+                printf("</TD>\n<TD align='center' nowrap style='color: #BBBBBB;'>&nbsp;%s&nbsp;", dateDisplay);
+            else
         printf("</TD>\n<TD align='center'>&nbsp;%s&nbsp;", dateDisplay);
+            }
+        }
 
     // End of row and free ourselves of this subtrack
     puts("</TD></TR>\n");
     checkBoxIdFree(&id);
     subgroupMembershipFree(&membership);
     }
 
 // End of the table
 puts("</TBODY><TFOOT>");
 printf("<TR valign='top'><TD colspan=%d>&nbsp;&nbsp;&nbsp;&nbsp;",columnCount-1);
 
 // Count of subtracks is filled in by javascript.
 if (slCount(subtrackRefList) > 5)
     printf("<span class='subCBcount'></span>\n");