coopcycle / coopcycle-app

CoopCycle native app
MIT License
152 stars 33 forks source link

The function "makeLabel" may return "Today between"/"Aujourd'hui entre" although the delivery is for tomorrow #1891

Closed Atala closed 1 month ago

Atala commented 1 month ago

delivery starts at 2024-10-03T15:08:00.000Z now is 2024-10-02T15:41:37.034

-> the delivery is for tomorrow but in Delivery.js it is displayed as "for today"

Image

the problem lies in makeLabel function I think. the calendarFormat function don't do what you think it does.

function makeLabel(range, now) {
  if (range.diff('days') === 0) {
    const nowClone = moment(now)
      .set('hour', range.start.get('hour'))
      .set('minute', range.start.get('minute'))
      .set('second', range.start.get('second'));

    console.error(range.start)
    console.error(now)
    console.error(moment.calendarFormat(range.start, nowClone))

    // This will return the key used in moment.calendar()
    // https://momentjs.com/docs/#/displaying/calendar-time/
    let calendarFormat = moment.calendarFormat(range.start, nowClone);
Atala commented 1 month ago

@alexsegura @vladimir-8

vladimir-8 commented 1 month ago
range.diff('days') === 0

If that's a way to check if it's today or not, then may be we should use something like moment('2010-01-01').isSame('2010-02-01', 'day'); instead

Atala commented 1 month ago

it is a way to check if the delivery dropoff is spanning on more than one days so this or moment(range.start).isSame(range.end, 'day') should do the same