@@ -8966,15 +8966,32 @@ public:
89668966
89678967
89688968 /+ +
8969- Converts this $(LREF TimeOfDay) to a string with the format HHMMSS.
8969+ Converts this $(LREF TimeOfDay) to a string with the format `HHMMSS`.
8970+ If `writer` is set, the resulting string will be written directly to it.
8971+
8972+ Params:
8973+ writer = A `char` accepting $(REF_ALTTEXT output range, isOutputRange, std, range, primitives)
8974+ Returns:
8975+ A `string` when not using an output range; `void` otherwise.
89708976 +/
89718977 string toISOString () const @safe pure nothrow
89728978 {
8973- import std.format : format;
8979+ import std.array : appender;
8980+ auto w = appender! string ();
8981+ w.reserve (6 );
8982+ toISOString(w);
8983+ return w.data;
8984+ }
8985+
8986+ // / ditto
8987+ void toISOString (W)(ref W writer) const
8988+ if (isOutputRange! (W, char ))
8989+ {
8990+ import std.format : formattedWrite;
89748991 try
8975- return format ( " %02d%02d%02d" , _hour, _minute, _second);
8992+ formattedWrite(writer, " %02d%02d%02d" , _hour, _minute, _second);
89768993 catch (Exception e)
8977- assert (0 , " format () threw." );
8994+ assert (0 , " formattedWrite () threw." );
89788995 }
89798996
89808997 // /
@@ -8996,15 +9013,32 @@ public:
89969013
89979014
89989015 /+ +
8999- Converts this $(LREF TimeOfDay) to a string with the format HH:MM:SS.
9016+ Converts this $(LREF TimeOfDay) to a string with the format `HH:MM:SS`.
9017+ If `writer` is set, the resulting string will be written directly to it.
9018+
9019+ Params:
9020+ writer = A `char` accepting $(REF_ALTTEXT output range, isOutputRange, std, range, primitives)
9021+ Returns:
9022+ A `string` when not using an output range; `void` otherwise.
90009023 +/
90019024 string toISOExtString () const @safe pure nothrow
90029025 {
9003- import std.format : format;
9026+ import std.array : appender;
9027+ auto w = appender! string ();
9028+ w.reserve (8 );
9029+ toISOExtString(w);
9030+ return w.data;
9031+ }
9032+
9033+ // / ditto
9034+ void toISOExtString (W)(ref W writer) const
9035+ if (isOutputRange! (W, char ))
9036+ {
9037+ import std.format : formattedWrite;
90049038 try
9005- return format ( " %02d:%02d:%02d" , _hour, _minute, _second);
9039+ formattedWrite(writer, " %02d:%02d:%02d" , _hour, _minute, _second);
90069040 catch (Exception e)
9007- assert (0 , " format () threw." );
9041+ assert (0 , " formattedWrite () threw." );
90089042 }
90099043
90109044 // /
@@ -9047,12 +9081,24 @@ public:
90479081 `fromISOString` and `fromISOExtString`.
90489082
90499083 The format returned by toString may or may not change in the future.
9084+
9085+ Params:
9086+ writer = A `char` accepting $(REF_ALTTEXT output range, isOutputRange, std, range, primitives)
9087+ Returns:
9088+ A `string` when not using an output range; `void` otherwise.
90509089 +/
90519090 string toString () const @safe pure nothrow
90529091 {
90539092 return toISOExtString ();
90549093 }
90559094
9095+ // / ditto
9096+ void toString (W)(ref W writer) const
9097+ if (isOutputRange! (W, char ))
9098+ {
9099+ toISOExtString(writer);
9100+ }
9101+
90569102 @safe unittest
90579103 {
90589104 auto tod = TimeOfDay (12 , 30 , 33 );
0 commit comments