Calendar start time in increments.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Emmker
    Member
    • Nov 2023
    • 79

    Calendar start time in increments.

    Is Τhere a away to create an event or activity, clicking on a timeline view, that automatically selects the closest 15' own the click event, as a start time?

    Meaning, if someone clicks on the timeline on the spot on picture 1, there modal that will open (pic 2) will have as the start time the closest 15' increment of the click, in that case 11:45

  • victor
    Active Community Member
    • Aug 2022
    • 755

    #2
    In the Timeline mode for EspoCRM Claendar, to indicate a more accurate time of the start of the event, you need to use the scroll on the mouse, namely, scroll to the precision of one minute (screenshot 1) -> click and create an event -> use the mouse scroll to return a convenient scale (15 minutes in your case).
    Attached Files

    Comment

    • Emmker
      Member
      • Nov 2023
      • 79

      #3
      Originally posted by victor
      In the Timeline mode for EspoCRM Claendar, to indicate a more accurate time of the start of the event, you need to use the scroll on the mouse, namely, scroll to the precision of one minute (screenshot 1) -> click and create an event -> use the mouse scroll to return a convenient scale (15 minutes in your case).
      Yes, but I have a request from a client to auto choose the closest 15' increment regardless of the scale of the timeline.

      I found a way, with this formula:

      Code:
      // 1) Extract all date/time parts
      $year = datetime\year(dateStart);
      $month = datetime\month(dateStart);
      $day = datetime\date(dateStart);
      $hour = datetime\hour(dateStart, 'UTC');
      $minutes = datetime\minute(dateStart);
      
      // 2) Initialize variables for rounded hour and minute
      $roundedHour = $hour;
      $roundedMinutes = 0;
      
      // 3) Decide which 15' block is closest
      ifThen(
      $minutes < 15,
      $roundedMinutes = 0
      );
      
      ifThen(
      $minutes >= 15 && $minutes < 30,
      $roundedMinutes = 15
      );
      
      ifThen(
      $minutes >= 30 && $minutes < 45,
      $roundedMinutes = 30
      );
      
      ifThen(
      $minutes >= 45 && $minutes <= 59,
      $roundedMinutes = 45
      );
      
      // 4) Build zero-padded strings for month, day, hour, minutes
      $monthString = $month;
      ifThen(
      $month < 10,
      $monthString = string\concatenate('0', $month)
      );
      
      $dayString = $day;
      ifThen(
      $day < 10,
      $dayString = string\concatenate('0', $day)
      );
      
      $hourString = $roundedHour;
      ifThen(
      $roundedHour < 10,
      $hourString = string\concatenate('0', $roundedHour)
      );
      
      $minuteString = $roundedMinutes;
      ifThen(
      $roundedMinutes < 10,
      $minuteString = string\concatenate('0', $roundedMinutes)
      );
      
      // 5) Concatenate into a valid datetime string (YYYY-MM-DD HH:mm)
      $newDateTime = string\concatenate(
      $year, '-',
      $monthString, '-',
      $dayString, ' ',
      $hourString, ':',
      $minuteString, ':00'
      );
      
      $diffInMinutes = datetime\diff($newDateTime, dateStart, 'minutes');
      dateStart = $newDateTime;
      dateEnd = datetime\addMinutes(dateEnd, $diffInMinutes );
      startTimePrint = dateStart
      That works fine.

      The problem now is that I cannot get that $newDateTime to show initialy, when the user clicks in the timeline.
      It only works, after the user saves the record.
      Any ideas about that?

      I think I need to change the modal view, in custom folders. But it is over my head.

      Comment

      Working...