Hello,
I am trying to setup a time range for a script. What I want to do for example is if the time is between “5:59 PM” and “6:01 PM”, i want to change the string to “6:00PM”. I have started on a script but what I am finding is that the AM/PM is ignored in the comparison so 5:59 AM in this script and would return TRUE even though it’s not actually in that range, which doesn’t really work for me. I’m not sure how to determine if a time falls within a range.
Ex.
set d to "5:56 AM" --Note: AM shouldn't return True but it does.
set s_ix to {bottomRange:"5:55 PM", topRange:"6:05 PM"}
set TR to topRange of s_ix
set BR to bottomRange of s_ix
if d ≥ BR and d ≤ TR then
return "Good"
end if
If anyone has an idea for me, it would be greatly appreciated.
Thank you
Dallas
I have it figured out in a round about way but if anyone knows how to do by actually comparing times please let me know
set d to "6:05 PM"
set timeOnly to characters 1 through -4 of d as string
set AmPM to last word of d
set s_ix to {bottomRange:"5:55", topRange:"6:05", tod:"PM"}
set topRange to topRange of s_ix
set bottomRange to bottomRange of s_ix
set tod to tod of s_ix
if AmPM = tod then
if timeOnly ≥ bottomRange and timeOnly ≤ topRange then
return "Good"
end if
end if
Thanks
Dallas
Hi Dallas,
your’re comparing strings, what do you expect?
ASCII equivalent of 5:56 AM is 53585354326577
ASCII equivalent of 5:55 PM is 53585353328077
5:56 is always greater than 5.55, regardless what’s coming next
Hi Stefan
I am aware they are strings, but is there a way to classify them as time so that I can do a proper time comparison? That is my question.
Thanks
Dallas
if you want to compare dates, use dates
set d to "5:56 AM"
set d1 to date d
set BRstring to "5:55 PM"
set TRstring to "6:05 PM"
set s_ix to {bottomRange:date BRstring, topRange:date TRstring}
set TR to topRange of s_ix
set BR to bottomRange of s_ix
if d1 ≥ BR and d1 ≤ TR then
return "Good"
end if
Thanks Stefan, that’s what I needed to know. I appreciate your help as always. Also you should be commended for the amount of help you provide to all the people that post on here. Your knowledge base is a great asset to all of us.
Thanks Again!
Dallas