Changeset 6277


Ignore:
Timestamp:
Jul 1, 2008, 10:35:32 PM (13 years ago)
Author:
charles
Message:

(gtk) #1070: 1:60 ???

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/util.c

    r6203 r6277  
    119119tr_strltime( char * buf, int seconds, size_t buflen )
    120120{
    121     int hours;
    122     int days;
     121    int days, hours, minutes;
     122    char d[128], h[128], m[128], s[128];
    123123
    124124    if( seconds < 0 )
    125125        seconds = 0;
    126126
    127     if( seconds < 60 )
    128     {
    129         g_snprintf( buf, buflen, ngettext( "%'d second", "%'d seconds", (int)seconds ), (int) seconds );
    130         return buf;
    131     }
    132 
    133     if( seconds < ( 60 * 60 ) )
    134     {
    135         const int minutes = ( seconds + 30 ) / 60;
    136         g_snprintf( buf, buflen, ngettext( "%'d minute", "%'d minutes", minutes ), minutes );
    137         return buf;
    138     }
    139 
    140     hours = seconds / ( 60 * 60 );
    141 
    142     if( seconds < ( 60 * 60 * 4 ) )
    143     {
    144         char h[64];
    145         char m[64];
    146 
    147         const int minutes = ( seconds - hours * 60 * 60 + 30 ) / 60;
    148 
    149         g_snprintf( h, sizeof(h), ngettext( "%'d hour", "%'d hours", hours ), hours );
    150         g_snprintf( m, sizeof(m), ngettext( "%'d minute", "%'d minutes", minutes ), minutes );
    151         g_snprintf( buf, buflen, "%s, %s", h, m );
    152         return buf;
    153     }
    154 
    155     if( hours < 24 )
    156     {
    157         g_snprintf( buf, buflen, ngettext( "%'d hour", "%'d hours", hours ), hours );
    158         return buf;
    159     }
    160 
    161     days = seconds / ( 60 * 60 * 24 );
    162     g_snprintf( buf, buflen, ngettext( "%'d day", "%'d days", days ), days );
     127    days = seconds / 86400;
     128    hours = (seconds % 86400) / 3600;
     129    minutes = (seconds % 3600) / 60;
     130    seconds = (seconds % 3600) % 60;
     131
     132    g_snprintf( d, sizeof( d ), ngettext( "%'d day", "%'d days", days ), days );
     133    g_snprintf( h, sizeof( h ), ngettext( "%'d hour", "%'d hours", hours ), hours );
     134    g_snprintf( m, sizeof( m ), ngettext( "%'d minute", "%'d minutes", minutes ), minutes );
     135    g_snprintf( s, sizeof( s ), ngettext( "%'d second", "%'d seconds", seconds ), seconds );
     136
     137    if( days ) {
     138        if( days >= 4 || !hours ) {
     139            g_strlcpy( buf, d, buflen );
     140        } else {
     141            g_snprintf( buf, buflen, "%s, %s", d, h );
     142        }
     143    } else if( hours ) {
     144        if( hours >= 4 || !minutes ) {
     145            g_strlcpy( buf, h, buflen );
     146        } else {
     147            g_snprintf( buf, buflen, "%s, %s", h, m );
     148        }
     149    } else if( minutes ) {
     150        if( minutes >= 4 || !seconds ) {
     151            g_strlcpy( buf, m, buflen );
     152        } else {
     153            g_snprintf( buf, buflen, "%s, %s", m, s );
     154        }
     155    } else {
     156        g_strlcpy( buf, s, buflen );
     157    }
     158
    163159    return buf;
    164160}
Note: See TracChangeset for help on using the changeset viewer.