@@ -1459,17 +1459,33 @@ package:
1459
1459
west).
1460
1460
+/
1461
1461
static string toISOString (Duration utcOffset) @safe pure
1462
+ {
1463
+ import std.array : appender;
1464
+ auto w = appender! string ();
1465
+ w.reserve (5 );
1466
+ toISOString(w, utcOffset);
1467
+ return w.data;
1468
+ }
1469
+
1470
+ // ditto
1471
+ static void toISOString (W)(ref W writer, Duration utcOffset)
1472
+ if (isOutputRange! (W, char ))
1462
1473
{
1463
1474
import std.datetime.date : DateTimeException;
1464
1475
import std.exception : enforce;
1465
- import std.format : format ;
1476
+ import std.format : formattedWrite ;
1466
1477
immutable absOffset = abs(utcOffset);
1467
1478
enforce! DateTimeException(absOffset < dur! " minutes" (1440 ),
1468
1479
" Offset from UTC must be within range (-24:00 - 24:00)." );
1469
1480
int hours;
1470
1481
int minutes;
1471
1482
absOffset.split! (" hours" , " minutes" )(hours, minutes);
1472
- return format (utcOffset < Duration.zero ? " -%02d%02d" : " +%02d%02d" , hours, minutes);
1483
+ formattedWrite(
1484
+ writer,
1485
+ utcOffset < Duration.zero ? " -%02d%02d" : " +%02d%02d" ,
1486
+ hours,
1487
+ minutes
1488
+ );
1473
1489
}
1474
1490
1475
1491
@safe unittest
@@ -1514,9 +1530,19 @@ package:
1514
1530
west).
1515
1531
+/
1516
1532
static string toISOExtString (Duration utcOffset) @safe pure
1533
+ {
1534
+ import std.array : appender;
1535
+ auto w = appender! string ();
1536
+ w.reserve (6 );
1537
+ toISOExtString(w, utcOffset);
1538
+ return w.data;
1539
+ }
1540
+
1541
+ // ditto
1542
+ static void toISOExtString (W)(ref W writer, Duration utcOffset)
1517
1543
{
1518
1544
import std.datetime.date : DateTimeException;
1519
- import std.format : format ;
1545
+ import std.format : formattedWrite ;
1520
1546
import std.exception : enforce;
1521
1547
1522
1548
immutable absOffset = abs(utcOffset);
@@ -1525,7 +1551,12 @@ package:
1525
1551
int hours;
1526
1552
int minutes;
1527
1553
absOffset.split! (" hours" , " minutes" )(hours, minutes);
1528
- return format (utcOffset < Duration.zero ? " -%02d:%02d" : " +%02d:%02d" , hours, minutes);
1554
+ formattedWrite(
1555
+ writer,
1556
+ utcOffset < Duration.zero ? " -%02d:%02d" : " +%02d:%02d" ,
1557
+ hours,
1558
+ minutes
1559
+ );
1529
1560
}
1530
1561
1531
1562
@safe unittest
0 commit comments