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

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

Open
Uggbert opened this issue Oct 11, 2024 · 5 comments
Open

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

Uggbert opened this issue Oct 11, 2024 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Uggbert
Copy link

Uggbert commented Oct 11, 2024

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):

  • macOS 15
  • IBM Notifier v 3.2.1

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

@Uggbert Uggbert added the bug Something isn't working label Oct 11, 2024
@SMartorelli SMartorelli changed the title [BUG] [BUG] Datepicker range issue with 12h time format Oct 11, 2024
@SMartorelli SMartorelli added this to the Version 3.3.0 milestone Oct 11, 2024
@SMartorelli SMartorelli self-assigned this Oct 11, 2024
@Macjutsu
Copy link

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
Copy link
Author

Uggbert commented Oct 14, 2024 via email

@SMartorelli
Copy link
Member

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
Copy link
Author

Uggbert commented Nov 18, 2024

@SMartorelli any update on this one?

@SMartorelli
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants