IBM / mac-ibm-notifications

macOS agent used to display custom notifications and alerts to the end user.
Apache License 2.0
298 stars 51 forks source link

[BUG] Datepicker range issue with 12h time format #228

Open Uggbert opened 1 month ago

Uggbert commented 1 month ago

Describe the bug Setting the system time to 12hr allows datepicker to go beyond the set /end_date

To Reproduce

  1. Set to 12hr time
  2. run -type popup -accessory_view_type datepicker -accessory_view_payload "/title Test /start_date 2024/10/11 17:34:36 /end_date 2024/10/24 00:00:00"
  3. able to select beyond /end_date
  4. Set 24hr system time
  5. run as above
  6. unable to select beyond /end_date

Expected behavior Regardless of 12hr or 24hr time, the user should not be able to select a date beyond the /end_date

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context First noticed this issue when using SUPERMAN, but was able to re-create with just Notifier.

Macjutsu commented 1 month ago

I can confirm this bug... but... only with the combination of UK Region settings (in Language & Region) along with 12 hour time format (in Date & Time)... fun!

I'm not sure if other regions have this bug... but if the Region is set to USA then both 12 and 24 hour time formats work.

Uggbert commented 1 month ago

Can confirm, I am using UK regional settings. Should have mentioned that at the time.

Kind Regards, Graeme Urquhart

On Mon, 14 Oct 2024 at 21:46, Kevin M. White @.***> wrote:

I can confirm this bug... but... only with the combination of UK Region settings (in Language & Region) along with 12 hour time format (in Date & Time)... fun!

I'm not sure if other regions have this bug... but if the Region is set to USA then both 12 and 24 hour time formats work.

— Reply to this email directly, view it on GitHub https://github.com/IBM/mac-ibm-notifications/issues/228#issuecomment-2412291676, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMF7CIBCOTRDXB5NYLOPN2TZ3QUSTAVCNFSM6AAAAABPZG24R6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJSGI4TCNRXGY . You are receiving this because you authored the thread.Message ID: @.***>

SMartorelli commented 1 month ago

Yes I was able to replicate it, I just need to check if it's an Apple bug or an IBM Notifier one. Will update this thread with the answer!

Uggbert commented 1 week ago

@SMartorelli any update on this one?

SMartorelli commented 1 week ago

It's a bit complicated to explain, but this issue relates to how Apple handles Date() and DatePicker() based on the system's time settings. Unfortunately, due to the lack of customization that still affects some SwiftUI components, this will be difficult to manage in IBM Notifier. However, there is a workaround that prevents the app from going off track. If your script is running on a machine with a 12-hour time setting, simply pass a 12-hour time-based value to IBM Notifier. For example, the DatePicker payload on a 12-hour time machine should look like this: /title Some Title /start_date 2024/10/11 10:34:36 AM /end_date 2024/10/24 10:00:00 PM. The output will then be in the same format (e.g. 2024-10-11 10:34:36 AM).

I've attached a small script I created that handles converting times back and forth. You can use it as an example.

#!/bin/bash

### Constants

# Detect if the system is using a 12-hour time format
is_12_hour_format=$(defaults read -g AppleICUForce12HourTime 2>/dev/null)

start_time="14:00:00"
start_date="2024/11/10"
preselected_time="14:01:00"
preselected_date="2024/11/10"
end_time="10:00:00"
end_date="2024/11/29"

ibm_notifier="/Applications/IBM Notifier.app/Contents/MacOS/IBM Notifier"

### Functions

prompt_user() {
    local -r start_date="${1}"
    local -r preselected_date="${2:- }"
    local -r end_date="${3}"
    local user_selection=$("$ibm_notifier" -type popup -title "title" -accessory_view_type "datepicker" -accessory_view_payload "/title Test /start_date $start_date /preselection $preselected_date /end_date $end_date")
    echo "$user_selection"
}

### Main

if [[ "$is_12_hour_format" -eq 1 ]]; then
    start_time=$(date -j -f "%H:%M:%S" "$start_time" +"%I:%M:%S %p")
    preselected_time=$(date -j -f "%H:%M:%S" "$preselected_time" +"%I:%M:%S %p")
    end_time=$(date -j -f "%H:%M:%S" "$end_time" +"%I:%M:%S %p")
fi

selected_date_and_time=$(prompt_user "$start_date $start_time" "$preselected_date $preselected_time" "$end_date $end_time")

if [[ "$is_12_hour_format" -eq 1 ]]; then
    temp_date=$(echo "$selected_date_and_time" | cut -d' ' -f1)
    temp_time=$(echo "$selected_date_and_time" | cut -d' ' -f2-)
    temp_time_fixed=$(echo "$temp_time" | tr -d '[:space:]')
    converted_time=$(date -j -f "%I:%M:%S %p" "$temp_time_fixed" +"%H:%M:%S")
    selected_date_and_time="$temp_date $converted_time"
fi

echo $selected_date_and_time