-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integration with <input type="time"> and <input type="date"> #107
Comments
let date = CivilDate.from(doument.getElementById('date').value);
let time = CivilTime.from(doument.getElementById('time').value);
let datetime = CivilDateTime.from(date, time);
let localdatetime = datetime.withZone('SYSTEM');
let timezoneOffsetSeconds = localdatetime.offsetSeconds;
let timezoneOffsetString = localdatetime.offsetString;
let timezoneName = localdatetime.timeZone;
ajax({
"method": "POST",
"url": "/api/schedule-appointment",
"payload": localdatetime // serializes to "2019-03-21T09:32:24.012307238-04:00[America/New_York]" (as of this post)
});
// No need to pass the timezone separately. A ZonedDateTime has both the absolute time and zone |
thx. but say i want to directly save ajax-result to sql-table that manages appointments across the u.s. i obviously want the dates normalized to utc so they're sortable (regardless of region). can you fill in the ???: var localdatetime;
localdatetime = CivilDateTime.from(
CivilDate.from(document.getElementById("date").value),
CivilTime.from(document.getElementById("time").value)
).withZone("SYSTEM");
ajax({
"method": "POST",
"url": "/api/schedule-appointment",
"payload": JSON.stringify({
// sortable utc-datetime saved to sql-table
datetime_utc: ???,
// metadata for future presentation-logic
timezoneOffset: localdatetime.offsetSeconds / 60,
...
})
}); |
ajax({
"method": "POST",
"url": "/api/schedule-appointment",
"payload": {
utcdate: localdatetime.instant, // stringifies to 2019-03-21T14:47:01.012352312Z
timezone: localdatetime.timeZone // either IANA-Name or the offsetString (-05:00),
offset: localdatetime.offsetSeconds
}
}); |
suggest this common use-case be added to README |
To be honest, I was contemplating not putting it in this issue, because it's very likely to be a bad idea. The way you do this by keeping it as the Take the following example: Your DB stores appointments. You want "all appointments on a specific date". With just the UTC date you can't do that selection even when storing timezone. So keeping the timezone and time in one value is fairly important. https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetimeoffset-transact-sql?view=sql-server-2017 would be an example. I'll be updating the FAQ soonish though |
different perspective. my experience has made me distrustful of datetime-magic, and keep most "business-logic" utc-only. for example in texas (+05:00 DST), i would want "all appointments on a specific [utc] datetime-range", e.g.: -- find all appointments on date 2019-03-22 in texas
SELECT * FROM appointment
-- filter by [timzoneoffset'd] utc-datetime-range
WHERE
'2019-03-22T05:00:00' <= appointment.utcdatetime
AND appointment.utcdatetime < '2019-03-23T05:00:00' |
@kaizhu256 That sounds like a good use case for the |
@littledan, yes
|
@kaizhu256 your use-case actually screams for OffsetDateTime, which is something we talked about last week. It’s bascially an Instant with a timezone offset that stringifies to an ISO-string with the offset (rather than IANA zone). No magic involved. |
@pipobscure, are
|
The creation of |
Creating types is half of this; the other half would be making a proposal in HTML for the new input methods. Let's continue tracking this. |
Here is a strawperson proposal:
Other ideas:
|
-1 for overengineering and unecessary coupling with temporal-proposal. here's a simpler strawperson-proposal using ISOStrings thats more cost-effective/library-agnostic: <!--
-- strawperson-proposal with simpler spec and UX
-- by introducing 2 extra isostrings
-- `valueZoned` and `valueUTC` for <input type="datetime-local">
-->
<input id="input1" type="datetime-local"
value = "2019-07-21T00:00:00"
valueZoned = "2019-07-21T00:00:00-05:00[America/Houston]"
valueUTC = "2019-07-21T05:00:00Z"
>
<script>
document.querySelector(
"#input1"
).addEventListener("change", function (evt) {
/*
* this function will handle change <evt> to get
* 1. value
* 2. valueZoned
* 3. valueUTC
*/
var civilZonedInstant;
var civilInstant;
var civilDatetime;
// get civil-object from #input1
civilDatetime = CivilDateTime.fromString( evt.target.value );
civilZonedInstant = ZonedInstant.fromString( evt.target.valueZoned );
civilInstant = Instant.fromString( evt.target.valueUTC );
// output civil-object to #input1
evt.target.value = JSON.stringify(civilDatetime);
evt.target.valueZoned = JSON.stringify(civilZonedInstant);
evt.target.valueUTC = JSON.stringify(civilInstant);
...
});
</script> this is perfect for the common-scenario where you're just baton-passing isostrings between user <-> dom <-> backend (and bypass civil-classes entirely). |
that came off harsh. i don't want heavy-handed coupling between and temporal-proposal that locks them into future-interoperability commitments that can be avoided. i do appreciate @domenic's original strawman for getting the ball-rolling and understanding the UX. |
Anything that requires passing around strings, instead of instances, isn’t going to be viable. |
Yes. We have no intention of adding more stringly-typed APIs to HTML or ES. |
why is it not viable? |
Strings are brittle. They are hard to validate, hard to identify, there’s no way of attaching methods/behavior to them; programmer intention is hard to make clear, as there is often overlap for a given string between more than one potential domain out of infinite domains. |
@domenic presented a good proposal in #107 (comment) . Thanks for the help! I think this is all we need for now; after Stage 3, we can raise this as an HTML proposal. We should also cross-reference @domenic 's proposal when we file again for a TAG review (#102 ). Other than that, I don't think any more action is needed for now. So, I'm removing this from the Stage 3 milestone and Finalize spec text project. |
strings are easy to serialize, You can easily serialize forms that have value types but as soon as You go with any objects You are done for, and need some kind of adapter in place. |
@criskrzysiu a string is already serialized, and yes, you do need to define your serialization algorithm. I'm not sure how that changes anything. |
I'd suggest using different accessors for each Temporal type (e.g.
|
Please no! Individual accessors are not a good idea. Also these already export an ISO string, so just use the temporal from methods and leave these alone. (I'm very much with @domenic 's proposal) |
Sorry for this really dumb question, I know that this isn't part of this proposal, but since this proposal may require some HTML proposals I wanted to ask if there are any plans of creating an integration with and Temporal.PlainMonthDay? HTML support for date, date-time and so on has always been a little bit lackluster IMHO. This proposal could be the spark to change this. For yearly recurring events a "MonthDay" picker would be great! A type="month" picker does already exist, so why not a "month-day"/"yearless-date" picker? Sure this could be achived with two comboboxes, but it isn't the same UX as with type="date" or type="month". I just would love to see a full integration of temporal (maybe even with all possible permutations or even timezone selection) with an input component. |
@rene-stesl Adding new input types sounds like an exciting initiative, but is not part of this proposal. I don't know of any existing plans, but maybe it's something you'd be interested in raising? |
This is out of scope. The implementation of Temporal is managed by EcmaScript, not the W3C. For more information, visit EcmaScript proposal stages. Your question would be more appropriate for W3C Submission Guidelines. |
referenced from w3ctag-review
according to MDN, the input-values would be [1], [2]:
what would UX-workflow integration look like? how would i use temporals to transform
<input type="date">, <input type="time">
into JSONdatetime_utc, timezoneOffset
?[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
[2] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time
The text was updated successfully, but these errors were encountered: