aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std/datetime
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2021-12-05 17:11:12 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2021-12-09 00:58:58 +0100
commit0fb57034770aa20adced4d176f34ca611c2945bf (patch)
tree1f5735c8b4f25aa4a290e5ae8124713c24f98359 /libphobos/src/std/datetime
parentc15aa46cca0649b68613d3292cf71c7cc57ef78f (diff)
downloadgcc-0fb57034770aa20adced4d176f34ca611c2945bf.zip
gcc-0fb57034770aa20adced4d176f34ca611c2945bf.tar.gz
gcc-0fb57034770aa20adced4d176f34ca611c2945bf.tar.bz2
d: Merge upstream dmd 568496d5b, druntime 178c44ff, phobos 574bf883b.
D front-end changes: - Import dmd v2.098.0 - New ImportC module for compiling preprocessed C11 code into D. - New -ftransition=in switch. - Improved handling of new 'noreturn' type. Druntime changes: - Import druntime v2.098.0 - Fix broken import in core.sys.linux.perf_event module (PR103558). Phobos changes: - Import phobos v2.098.0 - All sources are now compiled with -fpreview=fieldwise. gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 568496d5b. * Make-lang.in (D_FRONTEND_OBJS): Add d/common-file.o, d/common-outbuffer.o, d/common-string.o, d/file_manager.o, d/importc.o. Remove d/root-outbuffer.o. (d/common-%.o): New recipe. * d-builtins.cc (build_frontend_type): Update for new front-end interface. (d_build_d_type_nodes): Set noreturn_type_node. * d-codegen.cc (d_build_call): Don't call function if one of the arguments is type 'noreturn'. (build_vthis_function): Propagate TYPE_QUAL_VOLATILE from original function type. * d-frontend.cc (eval_builtin): Update signature. (getTypeInfoType): Likewise. (toObjFile): New function. * d-gimplify.cc (d_gimplify_call_expr): Always evaluate arguments from left to right. * d-lang.cc (d_handle_option): Handle OPT_ftransition_in. (d_parse_file): Don't generate D main if it is declared in user code. * d-tree.h (CALL_EXPR_ARGS_ORDERED): Remove. (enum d_tree_index): Add DTI_BOTTOM_TYPE. (noreturn_type_node): New. * decl.cc (apply_pragma_crt): Remove. (DeclVisitor::visit): Update for new front-end interface. (DeclVisitor::visit (PragmaDeclaration *)): Don't handle crt_constructor and crt_destructor pragmas. (DeclVisitor::visit (VarDeclaration *)): Don't generate declarations of type 'noreturn'. (DeclVisitor::visit (FuncDeclaration *)): Stop adding parameters when 'noreturn' type has been encountered. (get_symbol_decl): Set DECL_STATIC_CONSTRUCTOR and DECL_STATIC_DESTRUCTOR on decl node if requested. (aggregate_initializer_decl): Update for new front-end interface. * expr.cc (ExprVisitor::visit (CallExp *)): Always use the 'this' object as the result of calling any constructor function. (ExprVisitor::visit): Update for new front-end interface. * gdc.texi (Runtime Options): Document -fmain and -ftransition=in. * lang.opt (ftransition=in): New option. * modules.cc (get_internal_fn): Update for new front-end interface. * types.cc (TypeVisitor::visit): Likewise. (TypeVisitor::visit (TypeNoreturn *)): Return noreturn_type_node. (TypeVisitor::visit (TypeFunction *)): Stop adding parameters when 'notreturn' type has been encountered. Qualify function types that return 'noreturn' as TYPE_QUAL_VOLATILE. libphobos/ChangeLog: PR d/103558 * libdruntime/MERGE: Merge upstream druntime 178c44ff. * libdruntime/Makefile.am (DRUNTIME_DSOURCES_LINUX): Add core/sys/linux/syscalls.d. (DRUNTIME_DSOURCES_OPENBSD): Add core/sys/openbsd/pthread_np.d. * libdruntime/Makefile.in: Regenerate. * src/MERGE: Merge upstream phobos 574bf883b. * src/Makefile.am (D_EXTRA_DFLAGS): Add -fpreview=fieldwise. * src/Makefile.in: Regenerate. * testsuite/libphobos.exceptions/assert_fail.d: Update test. * testsuite/libphobos.betterc/test22336.d: New test.
Diffstat (limited to 'libphobos/src/std/datetime')
-rw-r--r--libphobos/src/std/datetime/systime.d52
-rw-r--r--libphobos/src/std/datetime/timezone.d1
2 files changed, 41 insertions, 12 deletions
diff --git a/libphobos/src/std/datetime/systime.d b/libphobos/src/std/datetime/systime.d
index 18b8524..4da1281 100644
--- a/libphobos/src/std/datetime/systime.d
+++ b/libphobos/src/std/datetime/systime.d
@@ -8308,12 +8308,17 @@ public:
YYYY-MM-DDTHH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ
is the time zone).
+ Default behaviour:
Note that the number of digits in the fractional seconds varies with the
number of fractional seconds. It's a maximum of 7 (which would be
hnsecs), but only has as many as are necessary to hold the correct value
(so no trailing zeroes), and if there are no fractional seconds, then
there is no decimal point.
+ The optional parameter "prec" allows to change the default behavior by
+ specifying the precision of the fractional seconds. The accepted values
+ are in the range [-1, 7], where -1 represents the default behavior.
+
If this $(LREF SysTime)'s time zone is
$(REF LocalTime,std,datetime,timezone), then TZ is empty. If its time
zone is `UTC`, then it is "Z". Otherwise, it is the offset from UTC
@@ -8325,25 +8330,30 @@ public:
Params:
writer = A `char` accepting
$(REF_ALTTEXT output range, isOutputRange, std, range, primitives)
+ prec = An `int` representing the desired precision. Acceptable values range from -1 to 7, where -1 represents the default behavior.
Returns:
A `string` when not using an output range; `void` otherwise.
+/
- string toISOExtString() @safe const nothrow scope
+ string toISOExtString(int prec = -1) @safe const nothrow scope
{
+ assert(prec >= -1 && prec <= 7, "Precision must be in the range [-1, 7]");
+
import std.array : appender;
auto app = appender!string();
app.reserve(35);
try
- toISOExtString(app);
+ toISOExtString(app, prec);
catch (Exception e)
assert(0, "toISOExtString() threw.");
return app.data;
}
/// ditto
- void toISOExtString(W)(ref W writer) const scope
+ void toISOExtString(W)(ref W writer, int prec = -1) const scope
if (isOutputRange!(W, char))
{
+ assert(prec >= -1 && prec <= 7, "Precision must be in the range [-1, 7]");
+
immutable adjustedTime = adjTime;
long hnsecs = adjustedTime;
@@ -8365,14 +8375,14 @@ public:
if (_timezone is LocalTime())
{
dateTime.toISOExtString(writer);
- fracSecsToISOString(writer, cast(int) hnsecs);
+ fracSecsToISOString(writer, cast(int) hnsecs, prec);
return;
}
if (_timezone is UTC())
{
dateTime.toISOExtString(writer);
- fracSecsToISOString(writer, cast(int) hnsecs);
+ fracSecsToISOString(writer, cast(int) hnsecs, prec);
put(writer, 'Z');
return;
}
@@ -8380,7 +8390,7 @@ public:
immutable utcOffset = dur!"hnsecs"(adjustedTime - stdTime);
dateTime.toISOExtString(writer);
- fracSecsToISOString(writer, cast(int) hnsecs);
+ fracSecsToISOString(writer, cast(int) hnsecs, prec);
SimpleTimeZone.toISOExtString(writer, utcOffset);
}
@@ -8401,6 +8411,15 @@ public:
assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)).toISOExtString() ==
"-0004-01-05T00:00:02.052092");
+
+ assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)).toISOExtString(4) ==
+ "-0004-01-05T00:00:02.0520");
+
+ assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)).toISOExtString(2) ==
+ "-0004-01-05T00:00:02.05");
+
+ assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)).toISOExtString(7) ==
+ "-0004-01-05T00:00:02.0520920");
}
@safe unittest
@@ -11025,32 +11044,41 @@ private:
/+
Returns the given hnsecs as an ISO string of fractional seconds.
+/
-string fracSecsToISOString(int hnsecs) @safe pure nothrow
+string fracSecsToISOString(int hnsecs, int prec = -1) @safe pure nothrow
{
import std.array : appender;
auto w = appender!string();
try
- fracSecsToISOString(w, hnsecs);
+ fracSecsToISOString(w, hnsecs, prec);
catch (Exception e)
assert(0, "fracSecsToISOString() threw.");
return w.data;
}
-void fracSecsToISOString(W)(ref W writer, int hnsecs)
+void fracSecsToISOString(W)(ref W writer, int hnsecs, int prec = -1)
{
import std.conv : toChars;
import std.range : padLeft;
assert(hnsecs >= 0);
+ if (prec == 0)
+ return;
+
if (hnsecs == 0)
return;
put(writer, '.');
auto chars = hnsecs.toChars.padLeft('0', 7);
- while (chars.back == '0')
- chars.popBack();
- put(writer, chars);
+
+ if (prec == -1)
+ {
+ while (chars.back == '0')
+ chars.popBack();
+ put(writer, chars);
+ }
+ else
+ put(writer, chars[0 .. prec]);
}
@safe unittest
diff --git a/libphobos/src/std/datetime/timezone.d b/libphobos/src/std/datetime/timezone.d
index 5df42e7..0527580 100644
--- a/libphobos/src/std/datetime/timezone.d
+++ b/libphobos/src/std/datetime/timezone.d
@@ -332,6 +332,7 @@ public:
version (Posix)
{
version (FreeBSD) enum utcZone = "Etc/UTC";
+ else version (OpenBSD) enum utcZone = "UTC";
else version (NetBSD) enum utcZone = "UTC";
else version (DragonFlyBSD) enum utcZone = "UTC";
else version (linux) enum utcZone = "UTC";