src/lib/edit.c
char *edit_utime(utime_t val, char *buf, int buf_len)
{
   char mybuf[200];
   static const int32_t mult[] = {60*60*24*365, 60*60*24*30, 60*60*24, 60*60, 60};
   static const char *mod[]  = {"year",  "month",  "day", "hour", "min"};
   int i;
   uint32_t times;

   *buf = 0;
   for (i=0; i<5; i++) {
      times = (uint32_t)(val / mult[i]);
      if (times > 0) {
         val = val - (utime_t)times * mult[i];
         bsnprintf(mybuf, sizeof(mybuf), "%d %s%s ", times, mod[i], times>1?"s":"");
         bstrncat(buf, mybuf, buf_len);
      }
   }
   if (val == 0 && strlen(buf) == 0) {
      bstrncat(buf, "0 secs", buf_len);
   } else if (val != 0) {
      bsnprintf(mybuf, sizeof(mybuf), "%d sec%s", (uint32_t)val, val>1?"s":"");
      bstrncat(buf, mybuf, buf_len);
   }
   return buf;
}
/*
 * Edit a utime "duration" into ASCII
 */
Edit a utime "duration" into ASCII
Edit a utime " duration " into ASCII
char *edit_utime(utime_t val, char *buf, int buf_len)
{
   char mybuf[200];
   static const int32_t mult[] = {60*60*24*365, 60*60*24*30, 60*60*24, 60*60, 60};
   static const char *mod[]  = {"year",  "month",  "day", "hour", "min"};
   int i;
   uint32_t times;
   *buf = 0;
   for (i=0; i<5; i++) {
      times = (uint32_t)(val / mult[i]);
      if (times > 0) {
         val = val - (utime_t)times * mult[i];
         bsnprintf(mybuf, sizeof(mybuf), "%d %s%s ", times, mod[i], times>1?"s":"");
         bstrncat(buf, mybuf, buf_len);
      }
   }
   if (val == 0 && strlen(buf) == 0) {
      bstrncat(buf, "0 secs", buf_len);
   } else if (val != 0) {
      bsnprintf(mybuf, sizeof(mybuf), "%d sec%s", (uint32_t)val, val>1?"s":"");
      bstrncat(buf, mybuf, buf_len);
   }
   return buf;
}
char * edit_utime ( utime_t val , char * buf , int buf_len ) { char mybuf [ 200 ] ; static const int32_t mult [ ] = { 60 * 60 * 24 * 365 , 60 * 60 * 24 * 30 , 60 * 60 * 24 , 60 * 60 , 60 } ; static const char * mod [ ] = { " " , " " , " " , " " , " " } ; int i ; uint32_t times ; * buf = 0 ; for ( i = 0 ; i < 5 ; i ++ ) { times = ( uint32_t ) ( val / mult [ i ] ) ; if ( times > 0 ) { val = val - ( utime_t ) times * mult [ i ] ; bsnprintf ( mybuf , sizeof ( mybuf ) , " " , times , mod [ i ] , times > 1 ? " " : " " ) ; bstrncat ( buf , mybuf , buf_len ) ; } } if ( val == 0 && strlen ( buf ) == 0 ) { bstrncat ( buf , " " , buf_len ) ; } else if ( val != 0 ) { bsnprintf ( mybuf , sizeof ( mybuf ) , " " , ( uint32_t ) val , val > 1 ? " " : " " ) ; bstrncat ( buf , mybuf , buf_len ) ; } return buf ; }
Edit a utime "duration" into ASCII
Edit a utime " duration " into ASCII