Tobias Gritschacher has submitted this change and it was merged.
Change subject: (bug 48145) Added time.Time.newFromIso8601
......................................................................
(bug 48145) Added time.Time.newFromIso8601
The time parser is currently not able to parse iso8601 in the form it is
returned by
time.Time.iso8601. This function serves as a workaround to compensate for now.
We require this since we want the TimeValue data value type to store the iso8601
representation rather than all fields separately. The TimeValue's JSON will
therefore
mainly consist of that iso8601 string from whom we have to create a new
TimeValue in
the frontend.
Change-Id: I19372290cef7f6a768f687373cac6be59c77474b
---
M DataValues/resources/time.js/time.Time.js
1 file changed, 20 insertions(+), 0 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DataValues/resources/time.js/time.Time.js
b/DataValues/resources/time.js/time.Time.js
index 2511ae7..1ce651f 100644
--- a/DataValues/resources/time.js/time.Time.js
+++ b/DataValues/resources/time.js/time.Time.js
@@ -161,6 +161,26 @@
return ( 1e12 + Math.abs( number ) + '' ).slice( -digits );
}
+ /**
+ * Creates a new Time object by a given iso8601 string.
+ *
+ * TODO: this function shouldn't really be required since the parser
should simply be able to
+ * take such a string and create a new Time object from it.
+ *
+ * @param {string} signature
+ * @param {number} [precision] If not given, precision will be as high
as possible.
+ */
+ Time.newFromIso8601 = function( iso8601String, precision ) {
+ // The parser only takes the iso8601 string in a certain format
right now. We have to bring
+ // it into that form first:
+ var formattedIso8601 = iso8601String
+ .replace( /T.+$/, '' ) // get rid of minutes (not
supported yet)
+ .replace( /([\-\+])?0*/, '$1' )// get rid of trailing
zeroes, keep "-" and "+"
+ .replace( '+', '' ); // get reid of "+"
+
+ return new Time( formattedIso8601, precision );
+ };
+
return Time; // expose time.Time
}( time ) );
--
To view, visit https://gerrit.wikimedia.org/r/61526
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I19372290cef7f6a768f687373cac6be59c77474b
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits