Date Time formatting final spec
| Release | Renderer status | Tasks status |
|---|---|---|
| Not scheduled | ✔️ .NET (#959) |
Implementation status
- [X] TypeScript (https://github.com/Microsoft/AdaptiveCards/pull/966)
- [x] UWP
- [ ] .NET (.NET uses DateTime.Parse and is therefore not strict enough)
- [x] iOS
- [x] Android
- [ ] Documentation
Problem
Given that ISO8601 has many accepted string formats (with and without hyphens, colons, timezone offset vs UTC, etc) it makes sense for us to clearly define a strict DATE/TIME function format and ensure all renderers adhere to it.
This will improve reliability for card authors and prevent unfortunate situations where a developer tests on one renderer and the date shows properly, but then the same payload goes to a different renderer and the user sees a weird {{DATE(....)}} string in the middle of the card.
Language support
Additionally, we need to know the language of the card to properly format the LONG DATE.
If the card is sent in English, but the user's device is in Spanish then the date formatting will take the device culture and format the long date into spanish, which will look really weird in the middle of english text.
Eg., this will look super weird to a user:
| Payload | Output |
|---|---|
"Your order was shipped {{DATE(2017-02-13T20:46:30Z, LONG)}}" |
"Your order was shipped Lunes, 13 de Febrero, 2017" |
Specification
AdaptiveCard lang attribute
- [ ] Add a
langattribute toAdaptiveCard
Consensus is to add a top-level property to AdaptiveCard to support the language. This aligns with HTML's design of <html lang="en">
Date/Time parsing spec
- CASE SENSITIVE (must be all caps)
- NO SPACES between the
{{,}}, or parentheses - STRICT RFC 3389 FORMATTING (See examples below)
- MUST BE a valid date and time
- ALL FAILURES MUST display the raw string in the card. No friendly message attempted. (The goal being to make the developer immediately aware there is a problem)
Valid formats
The only accepted format follows RFC 3389
YYYY "-" MM "-" DD "T" HH ":" MM ":" SS [OFFSET]
[OFFSET] may be the literal "Z" for UTC, or an hour-minute offset, seen below:
2017-02-14T06:08:00Z
2017-02-14T06:08:00-07:00
2017-02-14T06:08:00+07:00
Date Formatting
The DATE function allows an optional formatting param to tailor to output string.
- OPTIONAL space allowed before LONG/SHORT/COMPACT (RegEx:
/w+) - CASE SENSITIVE (must be all caps)
- Any UNKNOWN format param should fall-back to COMPACT (to future proof the parameter)
| Format | Example |
|---|---|
| COMPACT (Default) | "2/13/2017" |
| SHORT | "Mon, Feb 13th, 2017" |
| LONG | "Monday, February 13th, 2017" |
Time Formatting
The TIME function does not have a formatting param and should not include the seconds. E.g., "6:01 PM" or "18:01"
Examples
The follow examples cover the requirements above. The VALID formats should render correctly. The INVALID sections should return the date {{DATE}} / {{TIME}} string
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"lang": "en",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "VALID DATE / TIME FORMATS",
"size": "large",
"color": "good"
},
{
"type": "TextBlock",
"text": "No offset {{DATE(2017-02-14T06:08:00Z)}} {{TIME(2017-02-14T06:08:00Z)}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Positive offset {{DATE(2017-02-14T06:08:00+04:00)}} {{TIME(2017-02-14T06:08:00+04:00)}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Negative offset {{DATE(2017-02-14T06:08:00-07:00)}} {{TIME(2017-02-14T06:08:00-07:00)}}",
"wrap": true
}
]
},
{
"type": "Container",
"spacing": "large",
"items": [
{
"type": "TextBlock",
"text": "VALID DATE FORMAT OPTIONS",
"size": "large",
"color": "good"
},
{
"type": "TextBlock",
"text": "{{DATE(2017-02-14T06:08:00Z, COMPACT)}} (Default)",
"wrap": true
},
{
"type": "TextBlock",
"text": "{{DATE(2017-02-14T06:08:00Z, SHORT)}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "{{DATE(2017-02-14T06:08:00Z, LONG)}}",
"wrap": true
}
]
},
{
"type": "Container",
"spacing": "large",
"items": [
{
"type": "TextBlock",
"text": "INVALID DATE / TIME FORMATS",
"size": "large",
"color": "attention"
},
{
"type": "TextBlock",
"text": "Invalid Spaces {{ DATE(2017-02-14T06:08:00Z) }} {{ TIME(2017-02-14T06:08:00Z) }}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Invalid Date {{DATE(2017-99-14T06:08:00Z)}} {{TIME(2017-99-14T06:08:00Z)}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Invalid casing {{date(2017-02-14T06:08:00Z)}} {{Time(2017-02-14T06:08:00Z)}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Missing seconds {{DATE(2017-10-27T22:27Z)}} {{TIME(2017-10-27T22:27:00Z)}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "TIME doesn't allow a format param {{TIME(2017-02-14T06:08:00Z, SHORT)}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "{{DATE(2017-02-14T06:08:00Z, RANDOMTEXT)}}"
}
]
}
]
}
Auto-generated task status
- [x] .NET
I favor having a lang property at the card level, but regardless of the chosen option:
- What will be the list of valid language values? Will we be using the BCP 47 format?
- How do we map them to the various platforms our renderers run on? Is BCP 47 supported on all of them?
- Do we want to support fallback locales as JavaScript does?
Why only support UTC? And if we support only UTC why do we need the trailing Z? I think we should should support the full format as we currently do.
What value does supporting the offsets give card authors? Most date-time libraries work by transforming any date with offset into a utc time and then converting to the local timezone. It's just as easy for a card author to go from their local time to UTC as it is for the renderers.
If we support offests, which format of offset are we going to support? 2017-02-14T06:08:00-6 2017-02-14T06:08:00-6:30 2017-02-14T06:08:00-630
Are all valid according to the standard, but only the first format is valid for the Typescript renderer right now. If we're going to limit the offset format, I believe there's little value in having it.
Additionally, the typescript renderer only accepts negative offsets, 2017-02-14T06:08:00+6 is not recognized. And 2017-02-14T06:08:00-0 is valid although the standard says that it shouldn't.
Putting aside the bugs in the TypeScript renderer, which need to be fixed, the value is that this format is well known and understood. There might be scenarios that use an offset right now for all we know, and we would break them.
ISO 3339 isn't permissive as you say it is above, it is super strict:
date-fullyear = 4DIGIT
date-month = 2DIGIT ; 01-12
date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on month/year
time-hour = 2DIGIT ; 00-23
time-minute = 2DIGIT ; 00-59
time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second rules
time-secfrac = "." 1*DIGIT
time-numoffset = ("+" / "-") time-hour ":" time-minute
time-offset = "Z" / time-numoffset
partial-time = time-hour ":" time-minute ":" time-second [time-secfrac]
full-date = date-fullyear "-" date-month "-" date-mday
full-time = partial-time time-offset
date-time = full-date "T" full-time
I'm not saying we'd go as far as supporting the leap second rules (in JS at least the RegEx we use to do basic validation can be more permissive while the underlying platform does the heavy lifting) but I don't know why Adaptive would be the only example I know of only supporting UTC.
The only reason I bring up the issues with the typescript renderer is to illustrate how a "simple" addition like offsets can lend itself to becoming confusing.
If what you are suggesting is we adopt RFC 3339 as our date format instead of ISO 8601, then all the renderers should align to the RFC's spec. The RFC however is not really a standard, and non-web developers might still face issues when trying to represent their ISO 8601 compliant dates that are invalid according to the RFC. (As an example, ISO 8601 allows times without seconds, while in the RFC, and the proposal in this issue, only the second fractions are optional)
Seems like it's much easier to just take a small subset of what we need from the ISO standard, make it as strict as possible, and document that as what we allow in our payloads.
However, if we do feel accepting the offsets is a useful thing. I believe switching to RFC 3339 is a good way to go. It's by far less flexible than our currently documented ISO 8601.
So to confirm based on 3389, here are the final valid options, correct?
2017-02-14T06:08:00Z
2017-02-14T06:08:00-07:00
2017-02-14T06:08:00+07:00
I think we can go one step further, as in my experience that is how developers are using to using the format:
2017-02-14T06:08:00Z 2017-02-14T06:08:00-07 2017-02-14T06:08:00-07:30 2017-02-14T06:08:00+07 2017-02-14T06:08:00+07:30
Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10 [HxS - 16299 - 16.0.8730.2038]
From: Matt Hidinger [email protected] Sent: Tuesday, November 14, 2017 1:17:17 AM To: Microsoft/AdaptiveCards Cc: David Claux; Comment Subject: Re: [Microsoft/AdaptiveCards] Date Time formatting final spec (#908)
So to confirm based on 3389, here are the final valid options, correct?
2017-02-14T06:08:00Z 2017-02-14T06:08:00-07:00 2017-02-14T06:08:00+07:00
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FAdaptiveCards%2Fissues%2F908%23issuecomment-344103141&data=02%7C01%7Cdclaux%40microsoft.com%7C9d67208cb3d94480155608d52af510c5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636462154390728669&sdata=2Ef%2BsqvMnIzwPTr9Z3xl5hKCcUVHs6jhWjrb0Zsa64Y%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABRdoR020Cl2rKyr4Fe0-XD5gAxCXpAhks5s2NwMgaJpZM4QWvnb&data=02%7C01%7Cdclaux%40microsoft.com%7C9d67208cb3d94480155608d52af510c5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636462154390728669&sdata=2GGqmd3PifYwAwnwGkLs%2B73n3rviqej3b6X3SHJncXQ%3D&reserved=0.
But then we're neither ISO 8601 nor RFC 3389? In my opinion following 3389 would be the correct way to go, which would mean 2017-02-14T06:08:00-07 and 2017-02-14T06:08:00+07 should not be valid.
Indeed the point we are really trying to drive home is that consistency and reliability on all platforms should trump flexibility at this stage. We are implementing this time parsing/rending code on ~8 platforms and it's important that they all behave exactly the same. That's why we really need to nail this spec, document it well for card authors, and implement it the exact same way everywhere before we ship.
RFC 3389 seems good. Anything else should fail. That work for everyone?
Sure.
Get Outlook for Androidhttps://aka.ms/ghei36
From: Matt Hidinger [email protected] Sent: Tuesday, November 14, 2017 5:50:29 PM To: Microsoft/AdaptiveCards Cc: David Claux; Comment Subject: Re: [Microsoft/AdaptiveCards] Date Time formatting final spec (#908)
Indeed the point we are really trying to drive home is that consistency and reliability on all platforms should trump flexibility at this stage. We are implementing this time parsing/rending code on ~8 platforms and it's important that they all behave exactly the same. That's why we really need to nail this spec, document it well for card authors, and implement it the exact same way everywhere before we ship.
RFC 3389 seems good. Anything else should fail. That work for everyone?
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FAdaptiveCards%2Fissues%2F908%23issuecomment-344322304&data=02%7C01%7Cdclaux%40microsoft.com%7Cc1ae6d932dba4484400608d52b7fd0c8%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636462750319116433&sdata=bXvTW98E8%2BbBukPT1%2FNeNTyWILFybbbpT8gVZOsdsWU%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABRdoUB-ll73Kx74HtOdmd7d8C1857qoks5s2cTVgaJpZM4QWvnb&data=02%7C01%7Cdclaux%40microsoft.com%7Cc1ae6d932dba4484400608d52b7fd0c8%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636462750319116433&sdata=U203LhyREQ%2Fk3IkYUooGQZQifDHSPODH88ZsI%2FZmg5Y%3D&reserved=0.
Only thing concerns me is second fractions for offset. Are we going to allow it?
@ferventmoss no, the only deviation from 3389 would be the seconds fraction, we will not allow it. I'll uddate the spec with the latest from this thread
Thanks matt, stupid chrome signed me as Ferventmoss. sorry for the confusion if you had any! One last thing, time will be represented as hh:mm pm/am, right? e.g. 11:00 AM
@nesalang yeah that sounds correct to me
Is that something we can leave up to the time/date library? I noticed that when I switch my region, 10:57 AM becomes 10:57 a.m.
If not, I think hh:mm PM|AM is fine.
yes, it is handled by the time library.
I've updated the spec and good/bad payload examples for testing
One last thing - why impose case sensitiveness? It's only going to generate frustration and questions on support forums IMO. I'm fairly certain that all date/time parsing libraries out there are case insensitive, so implementation shouldn't be a problem. I know that being case insensitive isn't per RFC 3389, but it would just make things easier IMO.
Also, why would we allow spaces before the format specifier but not be case sensitive? Both are aimed at making things easier for the developer.
We haven't defined whether time formatting should include seconds. I believe it should not (there are calendaring scenarios in Outlook where including seconds just doesn't make any sense).
Thoughts?