Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3859

Show
Ignore:
Timestamp:
08/05/08 20:19:39 (4 months ago)
Author:
kris
Message:

added tentative format8601()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/text/convert/TimeStamp.d

    r3837 r3859  
    151151                            convert (tmp[8..10], time.minutes), 
    152152                            convert (tmp[10..12], time.seconds) 
     153                           ); 
     154} 
     155 
     156 
     157/****************************************************************************** 
     158 
     159        ISO-8601 format :: "2006-01-31T14:49:30Z" 
     160 
     161        Throws an exception where the supplied time is invalid 
     162 
     163******************************************************************************/ 
     164 
     165T[] format8601(T, U=Time) (T[] output, U t) 
     166{return format!(T)(output, cast(Time) t);} 
     167 
     168T[] format8601(T) (T[] output, Time t) 
     169{ 
     170        T[] convert (T[] tmp, long i) 
     171        { 
     172                return Integer.formatter!(T) (tmp, i, 'u', 0, 8); 
     173        } 
     174 
     175 
     176        assert (output.length >= 29); 
     177        if (t is t.max) 
     178            throw new IllegalArgumentException ("TimeStamp.format :: invalid Time argument"); 
     179 
     180        // convert time to field values 
     181        auto time = t.time; 
     182        auto date = Gregorian.generic.toDate (t); 
     183 
     184        // use the featherweight formatter ... 
     185        T[20] tmp = void; 
     186        return Util.layout (output, cast(T[]) "%0-%1-%2T%3%:%4:%5Z",  
     187                            convert (tmp[0..4], date.year), 
     188                            convert (tmp[4..6], date.month), 
     189                            convert (tmp[6..8], date.day), 
     190                            convert (tmp[8..10], time.hours), 
     191                            convert (tmp[10..12], time.minutes), 
     192                            convert (tmp[12..14], time.seconds) 
    153193                           ); 
    154194}