-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Extend token date handling to 'most' date fields #21584
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess there are a few cases, depending on the type of the underlying field:
timestamp
ordatetime
fields (egcivicrm_contribution.receive_date
) -- the token's default format should indicate both date and timedate
ortime
fields (egcivicrm_contact.birth_date
) -- the token's default format should indicate date xor time (respectively)My intuition is that this step here is the lossy part - ie we know the kind of MySQL
$field
we're looking at, but we output a PHPDateTime
object. ButDateTime
doesn't distinguish between temporal subtypes (time
/date
/datetime
/timestamp
). The lossiness will create a quirk where mostdatetime
/timestamp
data shows the time - but there is a 1/86,400 chance of displaying without the time. (Admittedly, that's not very high, but it is harder to reason about.)I think the only thing we could really do here is pass-through a richer object. For example, with something like https://gist.github.com/totten/185f4d7bf87e22f7fc363c85c756ba32, we could add a hint of the true type of the data:
Or we could attach a default format with something like: https://gist.github.com/totten/878177535912382fa298f80c5e456033
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten yeah the other thing is that how you use the data is a better indicator of whether you want the time to show than the metadata of the field. For example it's pretty commont to exclude time when recording contributions - but if you DO include it it's likely you would want to show it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten so in fact it's probably not the case that 'most datetime/timestamp data shows the time' - that would be true for timestamp but for many date time fields having no time is the norm not the exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch has six changes to the test-suite here which seem to be counter-examples... Skimming
civicrm-core@master:TokenConsistency.php
, it looks to me like most of the examples do have times.The exception is that
civicrm_case.start_date
andend_date
are pure-dates. But this makes sense because the MySQL type isdate
(ie those fields don't store times).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten I meant the norm in terms of how people actually use the database - ie it's hugely common not to record time unless it's meaningful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting from chat - pretty much every database I've ever seen has a gazillion date time records where the time is not filled in - eg. pretty much all imported contribution records have 'midnight' for their time. This is common across contributions, recurrings, pledges, etc etc
On the flip side a time of 'midnight' is really only meaningful in an event that really truly does start or end at midnight - which is rare but could be the case in a multizone event. Mitigating this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clicking-around to spot-check, there a few distinct behaviors:
12:00 AM
.)12:00 AM
.12:00 AM
.12:00 AM
.12:00 AM
.)12:00 AM
does show up.12:00 AM
.)12:00 AM
.datetime
, then both date+time are mandatory.datetime
fields. (It only usesdate
fields.)date
fields. Under the hood, they are saved with12:00 AM
. This is a consistent facade - the list/view/edit screens consistently hide the time component.(The above is about the backend UI. Separately, a very large portion of temporal data is specified under-the-hood -- eg logging (
*.created_date
,*.modified_date
,civicrm_subscription_history
,civicrm_mailing_job.start_date
, ad nauseum); also, records are often processed by self-service flows which autopopulate temporal data completely.)It seems to me that:
datetime
fields with a consistent facade -- a simulacrum ofdate
.datetime
fields are... well... date+time (together, as whole).datetime
is manually entered by a staff user, thetime
component is sometimes optional. But this is always flaky -- because blanktime
is coerced to12:00 AM
(which appears in search/browse/view/edit UIs; and which is indistinguishable from true12:00 AM
).12:00 AM
as a magical value - because (in practice) it doesn't get that treatment consistently, and (in principal) it's ambiguous and it complicates timezone-correctness. OTOH, I think you're right (in a probabilistic sense) that12:00 AM
is almost never literal - it is more likely to indicate a backend-user skipped that particular datum. Whatsmore,datetime
fields are prone to timezone problems... so maybe, on the whole, it's more accurate to show only the date...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten yeah - that's where I got to with it - the other big data source of data is imports & other input forms - which have a higher chance of having no time attached. The bit about 'not much happens at midnight' means that where contributions don't have a time (1% of them in the DB I just checked) they probably didn't happen at midnight (0% in the db I just checked)
What we are setting is a default that should be somewhat intuitive from a user point of view -- but imagine if you actually did have an event that started at midnight - probably at that point we are having the conversation about
a) helping people choose a format with the timezone included and
b) getting this working #21599 so it can output in the selected timezone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2 cents is that for the purposes of filling tokens, it's safe to assume that a time of
00:00:00
can be treated like "date only", as we are talking about a display value here.