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

[EN] Lava Date Filters Enhancement #3487

Closed
smross opened this Issue Dec 28, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@smross
Copy link

smross commented Dec 28, 2018

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:

Description

A clear and concise description of what the bug is, include screenshots if applicable.

Steps to Reproduce

  1. Open Lava Tester or put an HTML block on a page
  2. Assign a variable using the 'SundayDate' filter, for example {% assign ThisSunday = 'Now' | SundayDate %}
  3. Assign another variable using the same methodology, but piping a 'DateAdd' filter, for example {% assign ThisMonday = 'Now' | SundayDate | DateAdd:-6 %}
  4. Display your variables, for example <ul><li>This Sunday: {{- ThisSunday -}}</li><li>This Monday: {{- ThisMonday -}}</li></ul>

Expected behavior:

I expect the output/display to be consistent in it's formatting of the date and time. Sometimes it includes the time, sometimes it doesn't

Actual behavior:

Using the DateAdd filter after with the SundayDate date filter results in output formatting differently. I'm unsure if this also means it's going 'To Midnight' also, as I don't know of a foolproof way to examine the example I gave that doesn't use the DateAdd filter. It's not clear to me if using DateAdd always resets the hours/minutes/seconds to midnight, or if that's a function of the SundayDate filter
Example incorrect input & output:
input:

{% assign ThisSunday = 'Now' | SundayDate %}
{% assign ThisMonday = 'Now' | SundayDate | DateAdd:-6 %}
<ul>
  <li>
    This Sunday: {{- ThisSunday -}}
  </li>
  <li>
    This Monday: {{- ThisMonday -}}
  </li>
</ul>

Yields on output:

This Sunday:12/30/2018
This Monday:12/24/2018 12:00:00 AM

NOTE: This behavior is different if you change the order of use for the lava filters.... Using the SundayDate filter after the DateAdd filter does not result in output formatting being inconsistent. For this 2nd example
2nd Example input:

{% assign ThisSunday = 'Now' | SundayDate %}
{% assign ThisMonday = 'Now' | DateAdd:-6 | SundayDate %}
{% assign TwoSundays = 'Now' | DateAdd:-14 | SundayDate %}
{% assign TwoMondays = 'Now' | DateAdd:-20 | SundayDate %}
<strong>Reference:</strong>
<em>Weeks run 'Monday - Sunday'</em>
<ul>
  <li>
    Two prior Sundays: {{- TwoSundays -}}
  </li>
  <li>
    Two prior Mondays: {{- TwoMondays -}}
  </li>
  <li>
    This Sunday: {{- ThisSunday -}}
  </li>
  <li>
    This Monday: {{- ThisMonday -}}
  </li>
</ul>

2nd example output:

Two prior Sundays:12/16/2018
Two prior Mondays:12/9/2018
This Sunday:12/30/2018
This Monday:12/23/2018

Versions

  • Rock Version: [7.5], [8.4], [8.5]
  • Client Culture Setting: [en-US]
@nairdo

This comment has been minimized.

Copy link
Member

nairdo commented Jan 7, 2019

Hi @smross, as you've pointed out, the difference between your two examples calling the DateAdd filter either before or after SundayDate. Currently DateAdd manipulates date-time objects (and therefore returns a data time object), while the SundayDate filter always returns a string which is only the date portion. I'll need to discuss this internally, but we might be able to add another filter that behaves similar the C# ToShortDateString method.

@nairdo nairdo changed the title Inconsistent Lava Date Filters behavior [EN] Lava Date Filters Enhancement Jan 7, 2019

@smross

This comment has been minimized.

Copy link
Author

smross commented Jan 7, 2019

I don't know if it helps, but the context for this discovery was that I was attempting to use query string parameters with a Dynamic Data Block. In my example I was wanting to output data that happened in a date range. Since a date range also includes hours, minutes, and seconds, I had to come up with some way to get to midnight and 1 second before midnight. Or alternatively filter based on just the date part.

Maybe some notes about the affinity of each (which is just the date versus date & time) would help?

I obviously for my example wouldn't mind a date style filter that was date only based, as an alternative to the excellent existing DateAdd (which I'm understanding as date and time)

@nairdo

This comment has been minimized.

Copy link
Member

nairdo commented Jan 29, 2019

I updated the documentation for the SundayDate filter to make it clear about what it returns. https://www.rockrms.com/lava/filters/date-filters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment