Skip to content
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

Add {domain.now}, supporting |crmDate #21531

Merged
merged 8 commits into from
Sep 22, 2021
Merged

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Sep 19, 2021

Overview

Add new {domain.now} token - this provides the current date.

It also supports formatting and provides a mechanism for other dates to follow - ie the following work based on the formats configured in the date settings page.

Token example output
{domain.now} September 18th, 2021 11:58 PM
{domain.now|crmDate:"Datetime"} September 18th, 2021 11:58 PM
{domain.now|crmDate:"shortdate"} 09/18/2021
{domain.now|crmDate:"Full"} September 19th, 2010
{domain.now|crmDate:"Partial"} September 19th, 2010
{domain.now|crmDate:"Time"} 1:34 PM
{domain.now|crmDate:"Year"} 2010
{domain.now|crmDate:"FinancialBatch"} 09/19/2010
{domain.now|crmDate:"%B %Y"} September 202

Before

^^ not available

After

and now it is

Technical Details

This expands the range of what is considered a valid token-filter. The filters may now accept string-parameters, as in |crmDate:"first":"second":"third".

crmDate works if the token-value is defined as a \DateTime object (which I will do on the main entities as a follow up)

https://lab.civicrm.org/documentation/docs/user-en/-/merge_requests/498

@civibot
Copy link

civibot bot commented Sep 19, 2021

(Standard links)

@civibot civibot bot added the master label Sep 19, 2021
@eileenmcnaughton eileenmcnaughton changed the title Add {domain.now}, supporting |crmDate [not working yet - please help totten] Add {domain.now}, supporting |crmDate Sep 19, 2021
@totten
Copy link
Member

totten commented Sep 21, 2021

There was a problem where CRM_Core_DomainTokens populated {domain.now} but not {domain.now|crmDate:foo}. The problem was that the it didn't perceive domain.now as an active token... the active token list is built via TokenProcessor::addMessage() => CRM_Utils_Tokens::getTokens(). That function relies on an older regex.

I've added a bit here so that the same regex is always used by TokenProcessor::addMessage() and TokenProcessor::render().

Also, rebased/force-pushed

@eileenmcnaughton eileenmcnaughton changed the title [not working yet - please help totten] Add {domain.now}, supporting |crmDate Add {domain.now}, supporting |crmDate Sep 21, 2021
@eileenmcnaughton
Copy link
Contributor Author

@totten are you happy with this now, pending a PR template re-write & some thoughts about docs?

@totten
Copy link
Member

totten commented Sep 22, 2021

@eileenmcnaughton I've added several more tests, changed the notation to match Smarty (ie string-parameters are in quotes), and fixed the handling of %a/%b %c formatting expressions. Also updated description accordingly.

There are some limitations with string-parameters - e.g. it will not accept a quote-mark or curly-brace inside of a quoted string. But I don't think this is problematic with our target use-cases.

Date expressions that involve month/day names are sort of localized - ie if you have |crmDate:"%B", the token-stuff does what it should to output "April"(en), "Avril"(fr), or "Abril" (es). However, it doesn't work because CRM_Utils_Date has a caching bug. Sending up a separate PR to address that.

If you're happy with the updates, then I am too.

@eileenmcnaughton
Copy link
Contributor Author

Thanks @totten this looks good to me - it's actually quite exciting to think that we will have a non-hacky way to consolidate the various date handling (e.g I can update event badge tokens to use the token processor now it can support their preferred processing).

@seamuslee001 @colemanw @demeritcowboy can one of you MOP this

@eileenmcnaughton
Copy link
Contributor Author

@eileenmcnaughton
Copy link
Contributor Author

@colemanw
Copy link
Member

Code, docs & tests all look good.

@colemanw colemanw merged commit bd500f7 into civicrm:master Sep 22, 2021
@colemanw colemanw deleted the now branch September 22, 2021 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants