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

feat: ion-datetime with date range #23572

Open
Spinnenzunge opened this issue Jul 2, 2021 · 37 comments
Open

feat: ion-datetime with date range #23572

Spinnenzunge opened this issue Jul 2, 2021 · 37 comments
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement

Comments

@Spinnenzunge
Copy link

Feature Request

It would be great if the new ion-datetime would support a range feature (like for example in a hotel booking webpage) where you can provide a start and enddate and it shows on the calendar component.

xSaTg

Ionic version:

[ ] 4.x
[ ] 5.x
[x] 6.x

@ionitron-bot ionitron-bot bot added the triage label Jul 2, 2021
@willmartian willmartian added package: core @ionic/core package type: feature request a new feature, enhancement, or improvement labels Jul 3, 2021
@ionitron-bot ionitron-bot bot removed the triage label Jul 3, 2021
@willmartian willmartian added this to the 6.0.0 milestone Jul 3, 2021
@liamdebeasi liamdebeasi removed this from the 6.0.0 milestone Jul 6, 2021
@liamdebeasi liamdebeasi added the v6 issues specific to Framework v6 label Jul 6, 2021
@liamdebeasi liamdebeasi added type: feature request a new feature, enhancement, or improvement and removed type: feature request a new feature, enhancement, or improvement labels Jul 16, 2021
@jonatanmartinbabel
Copy link

We really need this, as long as we don't have this feature I still need to use tools external to Ionic

@Coder7777
Copy link

it's a very useful feature. we need it also.

@reslear
Copy link

reslear commented Jan 26, 2022

any news ?

@Weebsenpai
Copy link

We really need this, as long as we don't have this feature I still need to use tools external to Ionic

which external things are you using . I want to show multiple date range in same calendar is there any way you are aware about.

@j238
Copy link

j238 commented Mar 10, 2022

We really need this, as long as we don't have this feature I still need to use tools external to Ionic

which external things are you using . I want to show multiple date range in same calendar is there any way you are aware about.

https://www.npmjs.com/package/ion2-calendar
It's cool

@phyr0s
Copy link

phyr0s commented Jun 1, 2022

@liamdebeasi @willmartian almost one year from this request . Any news?

@reslear
Copy link

reslear commented Jun 1, 2022

is for vue, use https://vcalendar.io/datepicker.html

@jeremyw189
Copy link

jeremyw189 commented Aug 25, 2022

Not a great solution but this is what I am doing in Angular. It allows me to select one date or all dates between two selected dates.

HTML

<ion-datetime (ionChange)="dateChange()" [multiple]="true" [(ngModel)]="dateStrings" presentation="date"></ion-datetime>

TS

  // The value (one or multiple date strings).
  dateStrings: string[];

  // Cached values (used to prevent infinite date change events).
  private currentDateStrings: string[];

  dateChange() {
    // Detect changes (prevents an infinite loop).
    if (this.currentDateStrings === this.dateStrings) { return; }

    // Make sure we have at least two dates (otherwise nothing to do).
    if (!(this.dateStrings?.length > 1)) { return; }

    // Sort the dates so the earliest one is first.
    this.dateStrings.sort((a, b) => {
      if (a > b) { return 1; }
      else if (a < b) { return -1; }
      else { return 0; }
    });

    // Revert to single selection (if required).
    if (this.currentDateStrings?.length > 2) {
      for (const d of this.currentDateStrings) {
        if (this.dateStrings.indexOf(d) === -1) {
          // Make sure this is not the first or last date (those are handled natively).
          if (d === this.currentDateStrings[0]) { break; }
          if (d === this.currentDateStrings[this.currentDateStrings.length - 1]) { break; }

          this.dateStrings = [d];

          // No need to continue.
          break;
        }
      }
    }

    // Store the new value.
    const newValue = [];

    // Add all dates between the first and second dates.
    for (let d = new Date(this.dateStrings[0]); d <= new Date(this.dateStrings[this.dateStrings.length - 1]); d.setDate(d.getDate() + 1)) {
      newValue.push(this.getDateString(d));
    }

    // Update the values at the end so the UI gets updated only once.
    this.dateStrings = newValue;
    this.currentDateStrings = newValue;
  }

@Prabin1111
Copy link

any update about the ion-date-range range?

@mastercodingbear
Copy link

Is there any update about this feature?

@reslear
Copy link

reslear commented Nov 9, 2022

updates?

@liamdebeasi
Copy link
Contributor

Hi everyone,

We do not have any updates regarding this feature. Any updates will be posted on this thread as we have them.

@mastercodingbear
Copy link

Hi everyone,

We do not have any updates regarding this feature. Any updates will be posted on this thread as we have them.

Thanks, I have one question regarding a custom date range component which I'm making now.
I'm adding styles for the days in the range of dates but couldn't update UI when press the month next, prev buttons.
Could you possibly let me know how can I resolve this issue?
image

@codeforward101
Copy link

Also very interested in an update to this. Thanks.

@Ilijan91
Copy link

any update?

@extrordinaire
Copy link

Hello! Is there any update???

1 similar comment
@jlaci87
Copy link

jlaci87 commented Feb 7, 2023

Hello! Is there any update???

@atworkoxefit
Copy link

Following. This would be so helpful. Thanks.

@oluway
Copy link

oluway commented Jun 24, 2023

This could be helpful.

@WongSIuWing
Copy link

WongSIuWing commented Jun 30, 2023

I think a direction to fix this issue for the ionic developer could be adding a property in html element that stop year / month wheel emitting value automatically each time user click on the wheel.
Instead use a "cache date time" for the component to register the year / month updates from wheel and only emits a new date value after user click on a day.
Like so.
<ion-datetime [auto-emits]="false">
Or something like
<ion-datetime [emits-when]="day">

It's not a perfect solution but, at the moment, a very cost-effective way to unlock the possibility to make a day range component first that is bug free. Developer can actually implement a proper day-range with a work-around function (just play with the date array) once this feature is disabled.

@WongSIuWing
Copy link

WongSIuWing commented Jul 14, 2023

Hi everyone,
We do not have any updates regarding this feature. Any updates will be posted on this thread as we have them.

Thanks, I have one question regarding a custom date range component which I'm making now. I'm adding styles for the days in the range of dates but couldn't update UI when press the month next, prev buttons. Could you possibly let me know how can I resolve this issue? image

You can try to update ionic to v7, I had similar problem, where the calender value only emits once about user input in month and year.

update ionic to v7 solve the issue.

But then the calender updates the value everytime user spin the month and year wheel, its a disaster.

@liamdebeasi liamdebeasi added type: feature request a new feature, enhancement, or improvement and removed v6 issues specific to Framework v6 type: feature request a new feature, enhancement, or improvement labels Oct 5, 2023
@andres-espinoza
Copy link

At work we managed the range selection this way (using Ionic v7, Vue3 + TypeScript and Luxon):

Using the component

  <CustomDateRange
    id="datetime-filter" // Using a ion-datetime-button to open it
    min="2023-01-01T00:00:00"
    :start="startDate"
    :end="endDate"
    @update:start="(d) => (startDate = d)"
    @update:end="(d) => (endDate = d)"
  />
  
  const startDate = ref<string>('2023-10-01');
  const endDate = ref<string>('2023-10-23');

The component

<template>
  <ion-datetime
    class="clink-date-time-range"
    presentation="date"
    locale="es-ES"
    multiple
    :value="currentUserSelection"
    v-on:ion-change="handleDateChange"
    :highlighted-dates="defineHighlightStyle"
    v-bind="$attrs"
  />
</template>
<script setup lang="ts">
import { IonDatetime, DatetimeChangeEventDetail } from '@ionic/vue';
import { IonDatetimeCustomEvent, DatetimeHighlightCallback } from '@ionic/core';
import { onMounted, ref } from 'vue';
import { DateTime } from 'luxon';

interface ClinkDatetimeRange {
  start: string;
  end: string;
}

const props = defineProps<ClinkDatetimeRange>();
const emit = defineEmits<{
  (e: 'update:start' | 'update:end', date: string): void;
}>();

const currentUserSelection = ref<string[] | undefined>();
const previousUserSelection = ref<string[] | undefined>();

onMounted(() => {
  const initRange: string[] = [props.start, props.end];
  currentUserSelection.value = previousUserSelection.value = initRange;
});

const defineHighlightStyle: DatetimeHighlightCallback = (date: string) => {
  if (!currentUserSelection.value || currentUserSelection.value.length < 2)
    return;
  const startDateCurrentRange = DateTime.fromFormat(
    currentUserSelection.value[0],
    'yyyy-MM-dd'
  );
  const endDateCurrentRange = DateTime.fromFormat(
    currentUserSelection.value.at(-1) as string,
    'yyyy-MM-dd'
  );
  const formattedDate = DateTime.fromFormat(date, 'yyyy-MM-dd');
  const isDateWhithinRange =
    formattedDate > startDateCurrentRange &&
    formattedDate < endDateCurrentRange;

  if (isDateWhithinRange)
    return {
      backgroundColor: '#4818f717',
    };
};

const handleDateChange = (
  e: IonDatetimeCustomEvent<DatetimeChangeEventDetail>
) => {
  currentUserSelection.value = e.detail.value as string[] | undefined;

  if (!currentUserSelection.value && !previousUserSelection.value) return;

  if (!currentUserSelection.value || currentUserSelection.value.length < 2)
    return;

  currentUserSelection.value = [...currentUserSelection.value].sort((a, b) =>
    a > b ? 1 : -1
  );

  if (previousUserSelection.value && previousUserSelection.value.length >= 2) {
    const isSelectionWhithinPreviousRange =
      currentUserSelection.value.length < previousUserSelection.value.length;

    if (isSelectionWhithinPreviousRange) {
      const selectedDateWhithinPreviousRange =
        previousUserSelection.value.filter(
          (date) => !(currentUserSelection.value as string[]).includes(date)
        );
      currentUserSelection.value = selectedDateWhithinPreviousRange;
    } else {
      const lastUserSelection = [(e.detail.value as string[]).at(-1) as string];
      currentUserSelection.value = lastUserSelection;
    }
  }

  previousUserSelection.value = currentUserSelection.value;
  emit('update:start', currentUserSelection.value[0]);
  emit('update:end', currentUserSelection.value.at(-1) as string);
};
</script>

@lukasrgr
Copy link

lukasrgr commented Mar 8, 2024

did anybody manage to do this with angular 17?

@djabif
Copy link

djabif commented Mar 8, 2024

did anybody manage to do this with angular 17?

I'm using the library @googlproxer/ion-range-calendar with Angular 17 and Ionic 7 and it works like a charm.

Screenshot 2024-03-08 at 09 53 58

@lukasrgr
Copy link

@djabif is there a example to look at? cant seem to get it running

@djabif
Copy link

djabif commented Mar 11, 2024

@lukasrgr sorry but I can't share the code of this app but I can help you with the integration if you have any specific question

@sabrio
Copy link

sabrio commented Apr 19, 2024

This is essential for a framework, please have this consider.

@Coder7777

This comment was marked as off-topic.

@jprules321
Copy link

This needs to be added.

@Valvillavel
Copy link

Realmente necesitamos esto, mientras no tengamos esta característica, todavía necesito usar herramientas externas a Ionic

¿Qué cosas externas estás usando? Quiero mostrar varios rangos de fechas en el mismo calendario, ¿hay alguna forma que usted sepa?

https://www.npmjs.com/package/ion2-calendar Es genial

Is that component available for Angular Ivy?

@invot
Copy link

invot commented May 22, 2024

We really need this, as long as we don't have this feature I still need to use tools external to Ionic

which external things are you using . I want to show multiple date range in same calendar is there any way you are aware about.

https://www.npmjs.com/package/ion2-calendar It's cool

Doesn't this one only have official support for ionic 2, 3 & 4? Can you get it working on ionic 8?

@LennonReid
Copy link

We really need this, as long as we don't have this feature I still need to use tools external to Ionic

which external things are you using . I want to show multiple date range in same calendar is there any way you are aware about.

https://www.npmjs.com/package/ion2-calendar It's cool

Doesn't this one only have official support for ionic 2, 3 & 4? Can you get it working on ionic 8?

Hey there, I've upgraded this component to work with Ionic 6 and beyond. Feel free to check out the preview and the source code.

@danyal-satti
Copy link

i ma using ionic with standalone and i am getting problem with dayjs,any comment on it

@moh4sa
Copy link

moh4sa commented Jul 21, 2024

Do you have any tentative date for this feature?
It is an essential feature for a calendar component. even angular material supports it check it out here: link

@Weebsenpai
Copy link

Weebsenpai commented Jul 21, 2024 via email

@PaulliDev
Copy link

2024 Ionic 8 still no talks about this feature?

@reslear
Copy link

reslear commented Sep 3, 2024

I think they don't want to support it because it's not in apple.

but I would pay attention to the design https://github.com/simla-tech/Fastis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests