WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@fotrino
Copy link

@fotrino fotrino commented Oct 17, 2025

The scenario

When using <flux:daterange /> with a datepicker, users can either:

  1. Select a preset (Today, Yesterday, Last 7 Days, etc.)
  2. Manually select dates using the <flux:datepicker /> component

However, these two methods produce inconsistent end times:

  • Presets: End dates are set to 23:59:59 (end of day)
  • Manual selection: End dates are set to 00:00:00 (start of day)

This inconsistency causes issues when querying data, as the same date range selected via preset vs. datepicker produces different results.

The problem

Screen.Recording.2025-10-17.at.8.04.48.PM.mov

In src/DateRangeSynth.php, the set() method creates a new DateRange when the end date is updated via the datepicker:

function set(&$target, $key, $value) {
    $target = match ($key) {
        'start' => new DateRange($value, $target->end()),
        'end' => new DateRange($target->start(), $value),  // ← Problem: no endOfDay()
        'preset' => ...
    };
}

Meanwhile, all presets in src/DateRangePreset.php use endOfDay() for their end dates:

static::Today => [ Carbon::now()->startOfDay(), Carbon::now()->endOfDay() ],
static::Yesterday => [ Carbon::now()->subDay()->startOfDay(), Carbon::now()->subDay()->endOfDay() ],
// ... all other presets also use endOfDay()

The solution

Updated the set() method in DateRangeSynth.php to apply endOfDay() when setting the end date:

function set(&$target, $key, $value) {
    $target = match ($key) {
        'start' => new DateRange($value, $target->end()),
        'end' => new DateRange($target->start(), Carbon::parse($value)->endOfDay()),  // ← Fixed
        'preset' => ...
    };
}

This ensures that whether users select dates via presets or the datepicker, the end date is consistently set to 23:59:59, making date range queries work as expected.

Benefits:

  • Consistent behavior between presets and manual date selection
  • More intuitive for users (selecting "Jan 10" as end date now includes all of Jan 10)
  • Prevents off-by-one errors in date range queries

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant