From a684a0052dded288c28687ca9d2c35efc98ff1b7 Mon Sep 17 00:00:00 2001 From: UIMSolutions Date: Fri, 25 Oct 2024 07:21:10 +0200 Subject: [PATCH] Change Idatetime to Datetime --- .../uim/collections/classes/iterators/sort.d | 2 +- docs/api/classes/dtimehelper.html | 220 +++++++++--------- docs/api/interfaces/ICookie.html | 2 +- http/dub.sdl | 21 +- http/uim/http/classes/cookies/cookie (2).dx | 16 +- http/uim/http/classes/cookies/cookie.d | 12 +- http/uim/http/classes/cookies/factory.d | 4 +- .../uim/http/classes/responses/clients/vibe.d | 5 +- http/uim/http/classes/responses/emitter.d | 2 +- .../uim/http/classes/responses/servers/vibe.d | 2 +- http/uim/http/interfaces/cookie.d | 25 +- http/uim/http/interfaces/package.d | 1 + .../i18n/classes/formatters/relativetime.d | 2 +- i18n/uim/i18n/mixins/dateformat.d | 2 +- .../classes/validations/validation.d | 10 +- views/uim/views/classes/widgets/datetime.d | 182 ++++++++++++++- views/uim/views/classes/widgets/year.d | 2 +- views/uim/views/helpers/time.d | 2 +- 18 files changed, 345 insertions(+), 167 deletions(-) diff --git a/collections/uim/collections/classes/iterators/sort.d b/collections/uim/collections/classes/iterators/sort.d index 2264839610..3dbbf87be8 100644 --- a/collections/uim/collections/classes/iterators/sort.d +++ b/collections/uim/collections/classes/iterators/sort.d @@ -51,7 +51,7 @@ class DSortIterator : D_Collection { auto isDateTime = cast(DChronosDate) callbackValue || cast(DChronosTime) callbackValue || - cast(IDateTime) callbackValue; + cast(DateTime) callbackValue; if (isDateTime && sortType == SORT_NUMERIC) { callbackValue = callbackValue.format("U"); diff --git a/docs/api/classes/dtimehelper.html b/docs/api/classes/dtimehelper.html index 437ce54d8c..b1e00ba953 100644 --- a/docs/api/classes/dtimehelper.html +++ b/docs/api/classes/dtimehelper.html @@ -1,18 +1,18 @@ - - - - - - - - Class DTimeHelper - uim framework - - - - -
+ + + + + + + + Class DTimeHelper - uim framework + + + + +
- -
- -
-
-
- -
-
-
-
-

- Description -

-

- Time Helper class for easy use of time data. Manipulation of time data. -

-
-
-
-
- -
-
-
-
-

- Properties -

-

-

- - -
- - -
- - -
-

-
-
-
-
- -
-
-
-
-

- Methods -

-

-

InheritedAbstractFinalStaticDatatypeHeader
*/*/ /* if (options.hasKey("timezone") && cast(IDateTime) mydateTime)
-

-
-
-
-
- -
-
-
+ +
+ +
+
+
+ +
+
+
+
+

+ Description +

+

+ Time Helper class for easy use of time data. Manipulation of time data. +

+
+
+
+
+ +
+
+
+
+

+ Properties +

+

+

+ + +
+ + +
+ + +
+

+
+
+
+
+ +
+
+
+
+

+ Methods +

+

+

InheritedAbstractFinalStaticDatatypeHeader
*/*/ /* if (options.hasKey("timezone") && cast(DateTime) mydateTime)
+

+
+
+
+
+ +
+
+
- -
-
- - - + +
+ + + + diff --git a/docs/api/interfaces/ICookie.html b/docs/api/interfaces/ICookie.html index 951a6a0006..942e5ebe30 100644 --- a/docs/api/interfaces/ICookie.html +++ b/docs/api/interfaces/ICookie.html @@ -244,7 +244,7 @@

Methods

-

FinalDatatypeHeader
autoauto withDomain(string domainName)
boolbool isSecure()
stringstring value()
autoauto withPath(string aPath)
stringstring domain()
stringstring formattedExpires()
voidvoid withName(string aName)
withValue(string[]/*withValue(string[]/* |float|bool */ aValue)
boolbool isHttpOnly()
Json[string]Json[string] toArray()
stringstring getPath()
stringstring id()
string[]string[] getValue()
voidvoid withHttpOnly(bool httpOnly)
voidvoid withSecure(bool secure)
Json[string]Json[string] options()
IDateTimeIDateTime getExpiry()
autoauto withNeverExpire()
autoauto withExpiry(IDateTime dateTime)
autoauto withSameSite(/* SameSiteEnum| */string sameSite)
intint getExpiresTimestamp()
stringstring toHeaderValue()
+
FinalDatatypeHeader
autoauto withDomain(string domainName)
boolbool isSecure()
stringstring value()
autoauto withPath(string aPath)
stringstring domain()
stringstring formattedExpires()
voidvoid withName(string aName)
withValue(string[]/*withValue(string[]/* |float|bool */ aValue)
boolbool isHttpOnly()
Json[string]Json[string] toArray()
stringstring getPath()
stringstring id()
string[]string[] getValue()
voidvoid withHttpOnly(bool httpOnly)
voidvoid withSecure(bool secure)
Json[string]Json[string] options()
DateTimeDateTime getExpiry()
autoauto withNeverExpire()
autoauto withExpiry(DateTime dateTime)
autoauto withSameSite(/* SameSiteEnum| */string sameSite)
intint getExpiresTimestamp()
stringstring toHeaderValue()

diff --git a/http/dub.sdl b/http/dub.sdl index 6b47bb10ad..c4e82066b1 100644 --- a/http/dub.sdl +++ b/http/dub.sdl @@ -1,21 +1,18 @@ name "http" +description "D-Library for http requirements" homepage "https://" -license "Apache-2.0" -copyright "Copyright © 2017-2024, Ozan Nurettin Süel" authors "Ozan Nurettin Süel" - -description "D-Library for http requirements" - -dependency "colored" version="~>0.0.31" -dependency "vibe-d" version="~>0.10.0" - +copyright "Copyright © 2017-2024, Ozan Nurettin Süel" +license "Apache-2.0" dependency "uim:core" path="../" +dependency "vibe-core" version="~>2.9.5" +dependency "colored" version="~>0.0.31" +dependency "vibe-container" version="~>1.3.1" +dependency "vibe-d" version="~>0.10.1" +dependency "uim:models" path="../" dependency "uim:oop" path="../" dependency "uim:filesystems" path="../" -dependency "uim:models" path="../" targetType "library" - +targetName "uim-http" sourcePaths "." importPaths "." - -targetName "uim-http" diff --git a/http/uim/http/classes/cookies/cookie (2).dx b/http/uim/http/classes/cookies/cookie (2).dx index cb8da62b41..dfda0989aa 100644 --- a/http/uim/http/classes/cookies/cookie (2).dx +++ b/http/uim/http/classes/cookies/cookie (2).dx @@ -15,7 +15,7 @@ class DCookie : ICookie { protected bool _isExpanded = false; // Expiration time - protected IDateTime _expiresAt = null; + protected DateTime _expiresAt = null; protected string aPath = "/"; @@ -47,7 +47,7 @@ class DCookie : ICookie { this( string cookieName, string[] /* float|bool */ cookieValue = "", - IDateTime expiresAt = null, + DateTime expiresAt = null, string path = null, string domainName = null, bool isSecure = null, @@ -82,7 +82,7 @@ class DCookie : ICookie { * * Valid option keys are: * - * - `expires`: Can be a UNIX timestamp or `strtotime()` compatible string or `IDateTime` instance or `null`. + * - `expires`: Can be a UNIX timestamp or `strtotime()` compatible string or `DateTime` instance or `null`. * - `path`: A path string. Defauts to `'/'`. * - `domain`: Domain name string. Defaults to `""`. * - `httponly`: Boolean. Defaults to `false`. @@ -119,12 +119,12 @@ class DCookie : ICookie { ); } - // Converts non null expiry value into IDateTime instance. - protected static IDateTime dateTimeInstance(Json expires) { + // Converts non null expiry value into DateTime instance. + protected static DateTime dateTimeInstance(Json expires) { if (expires.isNull) { return null; } - if (cast(IDateTime)expires) { + if (cast(DateTime)expires) { return expires.setTimezone(new DateTimeZone("GMT")); } if (!isNumeric(expires)) { @@ -279,7 +279,7 @@ class DCookie : ICookie { } - IDateTime expires() { + DateTime expires() { return _expiresAt; } @@ -297,7 +297,7 @@ class DCookie : ICookie { return _expiresAt.format(EXPIRES_FORMAT); } - bool isExpired(?IDateTime time = null) { + bool isExpired(?DateTime time = null) { time = time ?: new DateTimeImmutable("now", new DateTimeZone("UTC")); if (cast(DateTime)time) { time = time.clone; diff --git a/http/uim/http/classes/cookies/cookie.d b/http/uim/http/classes/cookies/cookie.d index 935ffd1641..f5b1e5eb80 100644 --- a/http/uim/http/classes/cookies/cookie.d +++ b/http/uim/http/classes/cookies/cookie.d @@ -63,21 +63,25 @@ class DCookie : UIMObject, ICookie { return null; } + // Get the domain attribute. + string domain() { + return null; + } + // Get the timestamp from the expiration time int expiresTimestamp() { return 0; } - // Builds the expiration value part of the header string - string formattedExpires() { + string expiresString() { return null; } - // Get the domain attribute. - string domain() { + DateTime expiresDateTime() { return null; } + // Check if the cookie is HTTP only bool isHttpOnly() { return false; diff --git a/http/uim/http/classes/cookies/factory.d b/http/uim/http/classes/cookies/factory.d index 0b32932c14..2378b929ce 100644 --- a/http/uim/http/classes/cookies/factory.d +++ b/http/uim/http/classes/cookies/factory.d @@ -16,7 +16,7 @@ class DCookieFactory : DFactory!DCookie { } // Create a cookie with an updated expiration date - /* DCookie withExpiry(DCookie cookie, IDateTime dateTime) { + /* DCookie withExpiry(DCookie cookie, DateTime dateTime) { return null; } */ @@ -80,7 +80,7 @@ class DCookieFactory : DFactory!DCookie { return newCookie; } - /* DCookie withExpiry(DCookie cookie, IDateTime dateTime) { + /* DCookie withExpiry(DCookie cookie, DateTime dateTime) { auto newCookie = cookie.clone; if (cast(DateTime) dateTime) { diff --git a/http/uim/http/classes/responses/clients/vibe.d b/http/uim/http/classes/responses/clients/vibe.d index 701bc0b40a..4ba8dbf2d1 100644 --- a/http/uim/http/classes/responses/clients/vibe.d +++ b/http/uim/http/classes/responses/clients/vibe.d @@ -1,6 +1,7 @@ module uim.http.classes.responses.clients.vibe; import uim.http; +import vibe.container.dictionarylist; @safe: @@ -16,7 +17,7 @@ class DVibeClientResponse : UIMObject { private HTTPClientResponse _response; // The response header fields - DictionaryList/* !(string, false, 12L, false) */ headers; + DictionaryList!(string, false, 12L, false) headers; // The protocol version of the response - should not be changed HTTPVersion httpVersion; @@ -27,7 +28,7 @@ class DVibeClientResponse : UIMObject { // The status phrase of the response string statusPhrase; - DictionaryList/* !(vibe.http.common.Cookie, true, 32L, false) */ m_cookies; + DictionaryList!(vibe.http.common.Cookie, true, 32L, false) m_cookies; // #endregion Fields // #region Properties diff --git a/http/uim/http/classes/responses/emitter.d b/http/uim/http/classes/responses/emitter.d index 7a48a68bc9..04700843c3 100644 --- a/http/uim/http/classes/responses/emitter.d +++ b/http/uim/http/classes/responses/emitter.d @@ -155,7 +155,7 @@ class DResponseEmitter { } //Loops through the output buffer, flushing each, before emitting the response. - protected void flush(int maxBufferLevel = null) { + protected void flush(int maxBufferLevel = 0) { maxBufferLevel ? maxBufferLevel : ob_get_level(); while (ob_get_level() > maxBufferLevel) { diff --git a/http/uim/http/classes/responses/servers/vibe.d b/http/uim/http/classes/responses/servers/vibe.d index 349f46ddfd..6df13266c9 100644 --- a/http/uim/http/classes/responses/servers/vibe.d +++ b/http/uim/http/classes/responses/servers/vibe.d @@ -5,7 +5,7 @@ import uim.http; @safe: // Server response based on vibe implementation -class DVibeServerResponse { +class DVibeServerResponse : UIMObject { mixin(ResponseThis!("VibeServer")); } diff --git a/http/uim/http/interfaces/cookie.d b/http/uim/http/interfaces/cookie.d index 820ace7e42..81bf8ef7ab 100644 --- a/http/uim/http/interfaces/cookie.d +++ b/http/uim/http/interfaces/cookie.d @@ -16,26 +16,22 @@ interface ICookie : INamed { // The path / local URI for which the cookie is valid string path(); - void path(string value); // Get the domain attribute. - void domain(string name); string domain(); // Expiration date of the cookie - string expires(); - void expires(string datetime); + int expiresTimestamp(); + + string expiresString(); + DateTime expiresDateTime(); + // Get the current expiry time - // IDateTime expires(); + DateTime expires(); + // Get the timestamp from the expiration time int expiresTimestamp(); - // maxAge[get, set]long Maximum life time of the cookie - // rawValue[get, set] string Undecoded cookie payload - // secure[get, set]bool Require a secure connection for transmission of this cookie - // value[get, set] string Cookie payload - // Sets the cookie name - // Gets the cookie value string[] values(); @@ -48,15 +44,14 @@ interface ICookie : INamed { /** * Check if a cookie is expired when compared to time * Cookies without an expiration date always return false. */ - // TODO bool isExpired(IDateTime time = null); + bool isExpired(); + bool isExpired(DateTime time); // Check if the cookie is HTTP only - void isHttpOnly(bool mode); bool isHttpOnly(); // Get the SameSite attribute. - // TODO SameSiteEnum getSameSite(); - // sameSite[get, set] Cookie.SameSite Prevent cross - site request forgery. + SameSiteEnum getSameSite(); // Get cookie options Json[string] options(); diff --git a/http/uim/http/interfaces/package.d b/http/uim/http/interfaces/package.d index 64a619f4cb..76d43d42f7 100644 --- a/http/uim/http/interfaces/package.d +++ b/http/uim/http/interfaces/package.d @@ -17,6 +17,7 @@ public { import uim.http.interfaces.sessionhandler; import uim.http.interfaces.simplexml; import uim.http.interfaces.stream; + import uim.http.interfaces.table; import uim.http.interfaces.uploadedfile; import uim.http.interfaces.uri; } \ No newline at end of file diff --git a/i18n/uim/i18n/classes/formatters/relativetime.d b/i18n/uim/i18n/classes/formatters/relativetime.d index 46e50cd903..63c638101d 100644 --- a/i18n/uim/i18n/classes/formatters/relativetime.d +++ b/i18n/uim/i18n/classes/formatters/relativetime.d @@ -31,7 +31,7 @@ class DRelativeTimeFormatter { // }: DifferenceII18NFormatter { assert( (cast(DChronosDate) first && cast(DChronosDate) second) || - (cast(IDateTime) first && cast(IDateTime) second) + (cast(DateTime) first && cast(DateTime) second) ); auto diffInterval = first.diff(second); diff --git a/i18n/uim/i18n/mixins/dateformat.d b/i18n/uim/i18n/mixins/dateformat.d index 723ee57f14..d552c77a2e 100644 --- a/i18n/uim/i18n/mixins/dateformat.d +++ b/i18n/uim/i18n/mixins/dateformat.d @@ -18,7 +18,7 @@ mixin template TDateFormat() { // Returns a translated and localized date string. protected string _formatObject( - IDateTime date, + DateTime date, string[] aformat, string localName ) { diff --git a/validations/uim/validations/classes/validations/validation.d b/validations/uim/validations/classes/validations/validation.d index 9f1bb8c363..c10a894ef3 100644 --- a/validations/uim/validations/classes/validations/validation.d +++ b/validations/uim/validations/classes/validations/validation.d @@ -286,7 +286,7 @@ class DValidation : UIMObject, IValidation { } static bool date(Json value, string dateFormat = "ymd", string regex = null) { - /* if (cast(DChronosDate)value || cast(IDateTime)value) { + /* if (cast(DChronosDate)value || cast(DateTime)value) { return true; } */ if (value.isObject) { @@ -344,7 +344,7 @@ class DValidation : UIMObject, IValidation { * * All values matching the "date" core validation rule, and the "time" one will be valid */ - /* static bool isValidDatetime(IDateTime value, string[] mydateFormat = "ymd", string regex = null) { + /* static bool isValidDatetime(DateTime value, string[] mydateFormat = "ymd", string regex = null) { return true; } */ @@ -384,7 +384,7 @@ class DValidation : UIMObject, IValidation { * Validates an iso8601 datetime format * ISO8601 recognize datetime like 2019 as a valid date. */ - /* static bool isValidIso8601(IDateTime value) { + /* static bool isValidIso8601(DateTime value) { return true; } */ @@ -405,7 +405,7 @@ class DValidation : UIMObject, IValidation { * Params: * Json value a valid time string/object */ - /* static bool isValidTime(IDateTime value) { + /* static bool isValidTime(DateTime value) { return true; } */ @@ -426,7 +426,7 @@ class DValidation : UIMObject, IValidation { * Date and/or time string validation. * Uses `I18n.Time` to parse the date. This means parsing is locale dependent. */ - static bool isValidLocalizedTime(IDateTime dateValue, string parserType = "datetime", string /* int */ dateformat = null) { + static bool isValidLocalizedTime(DateTime dateValue, string parserType = "datetime", string /* int */ dateformat = null) { return true; } diff --git a/views/uim/views/classes/widgets/datetime.d b/views/uim/views/classes/widgets/datetime.d index be28a8ea3f..e9c73d659d 100644 --- a/views/uim/views/classes/widgets/datetime.d +++ b/views/uim/views/classes/widgets/datetime.d @@ -3,4 +3,184 @@ * License: Subject to the terms of the Apache 2.0 license, as written in the included LICENSE.txt file. * * Authors: Ozan Nurettin Süel (aka UIManufaktur) * *****************************************************************************************************************/ -module uim.views.classes.widgets.datetime; import uim.views; @safe: unittest { writeln("----- ", __MODULE__ , "\t -----"); } /** * Input widget class for generating a date time input widget. * * This class is usually used internally by `UIM\View\Helper\FormHelper`, * it but can be used to generate standalone date time inputs. */ class DDateTimeWidget : DWidget { mixin(WidgetThis!("DateTime")); override bool initialize(Json[string] initData = null) { if (!super.initialize(initData)) { return false; } /* configuration .setDefault("name", "") .setDefaults(["timezone", "val"], Json(null)) .setDefault("type", "datetime-local") .setDefault("escape", true) .setDefault("templateVars", Json.emptyArray); _formatMap = [ "datetime-local": "Y-m-d\\TH:i:s", "date": "Y-m-d", "time": "H:i:s", "month": "Y-m", "week": "Y-\\WW", ]; */ /** * Step size for various input types. * If not set, defaults to browser default. */ /* _defaultStep .set(["datetime-local", "time"], "1") .set(["date", "month", "week"], Json(null)); */ return true; } // alias _serialize = DSerializedView._serialize; // Formats for various input types. protected STRINGAA _formatMap; // Step size for various input types. Defaults = browser default. protected Json[string] _defaultStep; /** * Render a date / time form widget. * * Data supports the following keys: * * - `name` The name attribute. * - `val` The value attribute. * - `escape` Set to false to disable escaping on all attributes. * - `type` A valid HTML date/time input type. Defaults to "datetime-local". * - `timezone` The timezone the input value should be converted to. * - `step` The "step" attribute. Defaults to `1` for "time" and "datetime-local" type inputs. * You can set it to `null` or `false` to prevent explicit step attribute being added in HTML. * - `format` A `date()` auto compatible datetime format string. * By default, the widget will use a suitable format based on the input type and * database type for the context. If an explicit format is provided, then no * default value will be set for the `step` attribute, and it needs to be * explicitly set if required. * * All other keys will be converted into HTML attributes. */ override string render(Json[string] renderData, IContext formContext) { auto updatedData = renderData.merge(formContext.data); /* string typeName = updatedData.getString("type"); if (formatMap.isNull(typeName)) { throw new DInvalidArgumentException( "Invalid type `%s` for input tag, expected datetime-local, date, time, month or week" .format(typeName)); } */ /* updatedData = setStep(updatedData, formContext, updatedData.getString("fieldName")); updatedData.set("value", formatDateTime( updatedData.get("val") == true ? new DateTimeImmutable() : updatedData["val"], updatedData)); updatedData.removeKey("val", "timezone", "format"); return _stringContents.format("input", updatedData.data(["name", "type", "templateVars"]) .setPath(["attrs": _stringContents.formatAttributes( updatedData, ["name", "type"] )])); */ return null; } // Set value for "step" attribute if applicable. override protected Json[string] setStep(Json[string] data, IContext formContext, string fieldName) { /* if (hasKey("step", data)) { return data; } data.set("step", data.hasKey("format") ? null : this.defaultStep[data["type"]] ); if (data.isEmpty("fieldName")) { return data; } auto mydbType = formContext.type(fieldName); auto myfractionalTypes = [ TableDSchema.TYPE_DATETIME_FRACTIONAL, TableDSchema.TYPE_TIMESTAMP_FRACTIONAL, TableDSchema.TYPE_TIMESTAMP_TIMEZONE, ]; if (isIn(mydbType, myfractionalTypes, true)) { data.set("step", "0.001"); } return data; */ return null; } // Formats the passed date/time value into required string format. protected string formatDateTime( /* DChronosDate|ChronosTime| */ Json myvalue, Json[string] options) { /* if (myvalue is null || myvalue.isNull) { return null; } try { if (cast(IDateTime)myvalue || cast(DChronosDate)myvalue || cast(DChronosTime)myvalue) { mydateTime = myvalue.clone; } else if (isString(myvalue) && !isNumeric(myvalue)) { mydateTime = new DateTime(myvalue); } else if (isNumeric(myvalue)) { mydateTime = new DateTime("@" ~ myvalue); } else { mydateTime = new DateTime(); } } catch (Exception) { mydateTime = new DateTime(); } if (options.hasKey("timezone")) { mytimezone = options.get("timezone"); if (!cast(DateTimeZone)mytimezone) { mytimezone = new DateTimeZone(mytimezone); } mydateTime = mydateTime.setTimezone(mytimezone); } if (options.hasKey("format")) { myformat = options.get("format"); } else { myformat = formatMap[options.get("type")]; if ( options.getString("type") == "datetime-local" && isNumeric(options.get("step")) && options.getLong("step") < 1 ) { myformat = "Y-m-d\\TH:i:s.v"; } } return mydateTime.format(myformat); */ return null; } /* Json[string] secureFields(Json[string] data) { /* return data.isNull("name") || data.getString("name") is null ? null : [data["name"]]; * / return null; } */ } mixin(WidgetCalls!("DateTime")); unittest { assert(DateTimeWidget); } \ No newline at end of file +module uim.views.classes.widgets.datetime;DateTime + +import uim.views; + +@safe: + + unittest { + writeln("----- ", __MODULE__ , "\t -----"); +} + +/** + * Input widget class for generating a date time input widget. + * + * This class is usually used internally by `UIM\View\Helper\FormHelper`, + * it but can be used to generate standalone date time inputs. + */ +class DDateTimeWidget : DWidget { + mixin(WidgetThis!("DateTime")); + + override bool initialize(Json[string] initData = null) { + if (!super.initialize(initData)) { + return false; + } + /* configuration + .setDefault("name", "") + .setDefaults(["timezone", "val"], Json(null)) + .setDefault("type", "datetime-local") + .setDefault("escape", true) + .setDefault("templateVars", Json.emptyArray); + + _formatMap = [ + "datetime-local": "Y-m-d\\TH:i:s", + "date": "Y-m-d", + "time": "H:i:s", + "month": "Y-m", + "week": "Y-\\WW", + ]; */ + + /** + * Step size for various input types. + * If not set, defaults to browser default. + */ + /* _defaultStep + .set(["datetime-local", "time"], "1") + .set(["date", "month", "week"], Json(null)); */ + + return true; + } + // alias _serialize = DSerializedView._serialize; + // Formats for various input types. + protected STRINGAA _formatMap; + + // Step size for various input types. Defaults = browser default. + protected Json[string] _defaultStep; + + /** + * Render a date / time form widget. + * + * Data supports the following keys: + * + * - `name` The name attribute. + * - `val` The value attribute. + * - `escape` Set to false to disable escaping on all attributes. + * - `type` A valid HTML date/time input type. Defaults to "datetime-local". + * - `timezone` The timezone the input value should be converted to. + * - `step` The "step" attribute. Defaults to `1` for "time" and "datetime-local" type inputs. + * You can set it to `null` or `false` to prevent explicit step attribute being added in HTML. + * - `format` A `date()` auto compatible datetime format string. + * By default, the widget will use a suitable format based on the input type and + * database type for the context. If an explicit format is provided, then no + * default value will be set for the `step` attribute, and it needs to be + * explicitly set if required. + * + * All other keys will be converted into HTML attributes. + */ + override string render(Json[string] renderData, IContext formContext) { + auto updatedData = renderData.merge(formContext.data); + + /* string typeName = updatedData.getString("type"); + if (formatMap.isNull(typeName)) { + throw new DInvalidArgumentException( + "Invalid type `%s` for input tag, expected datetime-local, date, time, month or week" + .format(typeName)); + } */ + + /* updatedData = setStep(updatedData, formContext, updatedData.getString("fieldName")); + updatedData.set("value", formatDateTime( + updatedData.get("val") == true ? new DateTimeImmutable() : updatedData["val"], + updatedData)); + updatedData.removeKey("val", "timezone", "format"); + + return _stringContents.format("input", updatedData.data(["name", "type", "templateVars"]) + .setPath(["attrs": _stringContents.formatAttributes( + updatedData, ["name", "type"] + )])); */ + return null; + } + + // Set value for "step" attribute if applicable. + override protected Json[string] setStep(Json[string] data, IContext formContext, string fieldName) { + /* if (hasKey("step", data)) { + return data; + } + + data.set("step", data.hasKey("format") + ? null + : this.defaultStep[data["type"]] + ); + + if (data.isEmpty("fieldName")) { + return data; + } + auto mydbType = formContext.type(fieldName); + auto myfractionalTypes = [ + TableDSchema.TYPE_DATETIME_FRACTIONAL, + TableDSchema.TYPE_TIMESTAMP_FRACTIONAL, + TableDSchema.TYPE_TIMESTAMP_TIMEZONE, + ]; + + if (isIn(mydbType, myfractionalTypes, true)) { + data.set("step", "0.001"); + } + return data; */ + return null; + } + + // Formats the passed date/time value into required string format. + protected string formatDateTime( /* DChronosDate|ChronosTime| */ Json myvalue, Json[string] options) { + /* if (myvalue is null || myvalue.isNull) { + return null; + } + try { + if (cast(IDateTime)myvalue || cast(DChronosDate)myvalue || cast(DChronosTime)myvalue) { + mydateTime = myvalue.clone; + } else if (isString(myvalue) && !isNumeric(myvalue)) { + mydateTime = new DateTime(myvalue); + } else if (isNumeric(myvalue)) { + mydateTime = new DateTime("@" ~ myvalue); + } else { + mydateTime = new DateTime(); + } + } catch (Exception) { + mydateTime = new DateTime(); + } + if (options.hasKey("timezone")) { + mytimezone = options.get("timezone"); + if (!cast(DateTimeZone)mytimezone) { + mytimezone = new DateTimeZone(mytimezone); + } + mydateTime = mydateTime.setTimezone(mytimezone); + } + + if (options.hasKey("format")) { + myformat = options.get("format"); + } else { + myformat = formatMap[options.get("type")]; + + if ( + options.getString("type") == "datetime-local" + && isNumeric(options.get("step")) + && options.getLong("step") < 1 + ) { + myformat = "Y-m-d\\TH:i:s.v"; + } + } + return mydateTime.format(myformat); */ + return null; + } + + /* Json[string] secureFields(Json[string] data) { + /* return data.isNull("name") || data.getString("name") is null + ? null : [data["name"]]; * / + return null; + } */ +} + +mixin(WidgetCalls!("DateTime")); + +unittest { + assert(DateTimeWidget); +} \ No newline at end of file diff --git a/views/uim/views/classes/widgets/year.d b/views/uim/views/classes/widgets/year.d index a3e00f6000..78f4cc0ce0 100644 --- a/views/uim/views/classes/widgets/year.d +++ b/views/uim/views/classes/widgets/year.d @@ -62,7 +62,7 @@ class DYearWidget : DWidget { if ( cast(DChronosDate)mydata.get("val") || - cast(IDateTime)renderData.get("val") + cast(DateTime)renderData.get("val") ) { renderData.set("val", mydata.get("val").format("Y")); } diff --git a/views/uim/views/helpers/time.d b/views/uim/views/helpers/time.d index 07384cd0f3..b5ee3f414d 100644 --- a/views/uim/views/helpers/time.d +++ b/views/uim/views/helpers/time.d @@ -217,7 +217,7 @@ class DTimeHelper : DHelper { // myelement = null; /* auto options = options.merge(["element", "timezone"]); options.set("timezone", _getTimezone(options.get("timezone"))); - */ /* if (options.hasKey("timezone") && cast(IDateTime) mydateTime) { + */ /* if (options.hasKey("timezone") && cast(DateTime) mydateTime) { if (cast(DateTime) mydateTime) { mydateTime = mydateTime.clone; }