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

Time dependence selects different dates #935

Closed
2 tasks done
MichaelLiss opened this issue Apr 11, 2024 · 2 comments
Closed
2 tasks done

Time dependence selects different dates #935

MichaelLiss opened this issue Apr 11, 2024 · 2 comments
Labels
bug Something isn't working stale

Comments

@MichaelLiss
Copy link

MichaelLiss commented Apr 11, 2024

Before you start - checklist

  • I followed instructions in documentation written for my React-Calendar version
  • I have checked if this bug is not already reported

Description

let me preface this by saying I think THIS is how calendar dates should be returned:

    [
        "2024-01-28T07:00:00.000Z",
        "2024-01-29T07:00:00.000Z",
        "2024-01-30T07:00:00.000Z",
        "2024-01-31T07:00:00.000Z",
        "2024-02-01T07:00:00.000Z",
        "2024-02-02T07:00:00.000Z",
        "2024-02-03T07:00:00.000Z"
    ],

I think that if there is a calendar control that deals with dates .. .the hours - minutes - seconds should not "really matter".

The control does not have a "time" specified of the day you wish to start... it merely gives dates - If I am selecting a date range from 1 Apr 2024 to 3 Apr 2024 - the date range returned should be 1 Apr 2024 to 3 Apr 2024.

The 'tileDisabled' dates do not suggest an hours/minutes/seconds:

import { differenceInCalendarDays } from 'date-fns';


  const disabledDates = ['3-22-2024'];

  function tileDisabled({ date, view }) {
    // Disable tiles in month view only
    if (view === 'month') {
      // Check if a date React-Calendar wants to check is on the list of disabled dates
      return disabledDates.find((dDate) => isSameDay(dDate, date));
    }
  }

  function isSameDay(a, b) {
    return differenceInCalendarDays(a, b) === 0;
  }

<Calendar
onChange={setSelectedDates}
calendarType="gregory"
hover
minDate={now}
maxDate={maxDate}
value={selectedDates}
tileDisabled={tileDisabled}

minDate, and value do not include "time values" either

additionally, the function that sets the 'maxDate' (see addMonthsToDate ) does not take into account hours/minutes/seconds

  function addMonthsToDate(inputDate, months) {
    // Clone the input date to avoid modifying the original object
    var newDate = new Date(inputDate);

    // Get the current month and year
    var currentMonth = newDate.getMonth();
    var currentYear = newDate.getFullYear();

    // Calculate the new month and year after adding months
    var newMonth = (currentMonth + months) % 12;
    var newYear = currentYear + Math.floor((currentMonth + months) / 12);

    // Set the new month and year to the date object
    newDate.setMonth(newMonth);
    newDate.setFullYear(newYear);

    return newDate;
  }

  let now = new Date();
  let maxDate = addMonthsToDate(now, 12);

I am confused the calendar control deals with years/months/days with some aspects but then uses hours/minutes/seconds in others

Steps to reproduce

clicked on 1 Apr 2024 and then extended selection to 3 Apr 2024 and click on 3 Apr 2024

Expected behavior

I would expect the selected dates to be 1 Apr 2024 to 3 Apr 2024

Actual behavior

selectedDates is 1 Apr 2024 to 4 Apr 2024

and the time values are always the same:
"2024-04-11T06:00:00.000Z","2024-04-13T05:59:59.999Z"

Additional information

If you can provide sample code that will return the correct dates when a range is selected, regardless of what time zone the control is used - I would be happy with that

Environment

  • Browser (if applicable):
  • React-Calendar version:
  • React version:

I made my own control - which actually works -regardless of timezone !

image

@MichaelLiss MichaelLiss added the bug Something isn't working label Apr 11, 2024
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

@github-actions github-actions bot added the stale label Jul 15, 2024
Copy link
Contributor

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

1 participant