I need to capture the Sunday of a particular week selected with the Popup Calendar object and can’t find a script function to subtract days from the selected day. Basically, if a user clicks on Wednesday, February 11, 2015, I need to capture Sunday, February 8, 2015.
You can use java.util.Calendar to get the day of week:
Here’s a window to play with. Take note of the propertyChange script and custom properties of the calendar component.
StartOfWeek_2015-02-11_1005.proj (9.74 KB)
EDIT: Sorry for the way short answer. I got pressed for time and I wanted to have something ready for you.
The propertyChange script grabs the date, sets it to a java.util.Calendar object, and extracts the day of week. It then pops the result back out to the DOW custom property (minus 1-- more on that in a bit…).
if event.propertyName=='date':
from java.util import Calendar
d=event.source.latchedDate
c=Calendar.getInstance()
c.setTime(d)
event.source.DOW=c.get(Calendar.DAY_OF_WEEK)-1
The StartOfWeek custom property uses the expression:
dateArithmetic({Root Container.Calendar.date},
-({Root Container.Calendar.DOW}),
"day")
Now, to explain the ‘minus 1’ thing. In the java.util.Calendar, Sunday has a value of one. If we left it that way it was, would actually be taking away one more day than needed. So we subtract on up front to give us a true offset to the day of week.
Thanks Jordan. I did go back and add a custom property and used an expression to capture it.
switch({Root Container.Popup Calendar.DaySelected},
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
dateArithmetic({Root Container.Popup Calendar.date},-1,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-2,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-3,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-4,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-5,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-6,"day"),
{Root Container.Popup Calendar.date})
DaySelected is another custom property that is the day of week:
dateFormat({Root Container.Popup Calendar.date},"E")