Calendar widget
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Calendar widget
Mmmm, I wonder if it will be as happy on Windows.
Normal date handling in LCS on Windows will fail with dates pre 1970.
Normal date handling in LCS on Windows will fail with dates pre 1970.
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Calendar widget
Could someone give it a try and let me know? I don't have access to a Window's machine at the moment.
BTW, I've jazzed up the calendar widget a bit (see if you can spot the difference) and polished the conversion routines. I guess the next step is to try and deploy it in a stack. I'm hoping the popup widget command will do the trick.
Mark
- Attachments
-
- Calendar.livecode.zip
- (3.08 KiB) Downloaded 248 times
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Calendar widget
Pre 1970 if you click the convert button, it will show some "dateItems" (as generated by the functions in the card script, but which fail to be converted into a date format in the field instead of a formatted date.
Then trying to change the date via selecting the navigation arrows in the calendar widget pane gives an error: button "right": execution error at line 22 (LCB Error in file calendar.lcb at line 305: Value is not of correct type for assignment to variable - expected type <type: livecode.lang.number> for assigning to variable mSelectedYear in com.livecode.widget.calendar.)
Then trying to change the date via selecting the navigation arrows in the calendar widget pane gives an error: button "right": execution error at line 22 (LCB Error in file calendar.lcb at line 305: Value is not of correct type for assignment to variable - expected type <type: livecode.lang.number> for assigning to variable mSelectedYear in com.livecode.widget.calendar.)
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Calendar widget
Great, thanks all. Looks like the LC convert command is the limiting factor. It is probably Windows dependant in someway. When I get some spare moments I'll write a replacement (just specifically for this stack/solution). Shouldn't be too hard to work out.
Thanks, the feedback has been very helpful.
Mark
Thanks, the feedback has been very helpful.
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Calendar widget
Does anyone know if this will work with the popup widget command in LC? I tried making it work but I don't know how to get to be a reasonable size... it's just all squished up at the top left of the screen (I used 0,0 as a starting point ).
Thanks
Thanks
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Calendar widget
Hi Mark,
just tested here and I can confirm it does NOT woek as advertized!
-> Yep, it's just all squished up, no matter WHERE I let it popup.
So please bugreport this, thanks.
Best
Klaus
just tested here and I can confirm it does NOT woek as advertized!
-> Yep, it's just all squished up, no matter WHERE I let it popup.
So please bugreport this, thanks.
Best
Klaus
Re: Calendar widget
Hi Mark,
The example form the dictionary for popUp adapted to calendar widget:
That works if you pass it a reasonable rect
I guess it is not a bug.
Kind regards
Bernd
The example form the dictionary for popUp adapted to calendar widget:
Code: Select all
on mouseDown theButton
if theButton is 3 then
local tProps
put "200,200,500,500" into tProps["rect"]
popup widget "com.livecode.widget.calendar" with properties tProps
if the result is not "Cancel" then
put it
end if
else
pass mouseDown
end if
end mouseDown
I guess it is not a bug.
Kind regards
Bernd
Re: Calendar widget
Yes, this works!
Oh boy, I should also read the fineprint next time...
Oh boy, I should also read the fineprint next time...

Re: Calendar widget
And I also should be more precise:
the rect is best defined by starting at 0,0
So the line for the rect should read
Not starting at 0,0 did not hurt but is confusing.
Kind regards
Bernd
the rect is best defined by starting at 0,0
So the line for the rect should read
Code: Select all
put "0,0,200,200" into tProps["rect"]
Not starting at 0,0 did not hurt but is confusing.
Kind regards
Bernd
Re: Calendar widget
Just as an aside, the determination of whether a year is a leap year is not solely judged by whether it is divisible by 4. (1900, for instance is not a leap year. Century years must be divisible by 400 to be a leap year.)
Revised function:
Revised function:
Code: Select all
function isaLeap pYear
// returns true if it is a leap year
if pYear mod 4 is not 0 then return false
if pYear mod 100 is not 0 then return true
if pYear mod 400 is 0 then return true
return false
end isaLeap
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Calendar widget
Thanks, I wasn't sure what a good way to do that in LC would look like. Some other languages I've learned (notably Pascal) only allow 1 return value per function. So this solution did not occur to me. Its clever.
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Calendar widget
It's just a shorthand way of checking the conditions without wrapping in "if...else...end if" constructions. There's only ever one value returned. With (thankfully) lazy evaluation you get "condition test failed...meh" and moving on to the next statement without importance whether the action on true was to return a value or put "cheesecake" in tOven. If the test passed, then the return statement is actioned, and that return exits the handler without and further statements being processed.
I am big on verbosity and almost always put full if...end if statements, but on certain occasions the single liner can be neat.
I am big on verbosity and almost always put full if...end if statements, but on certain occasions the single liner can be neat.
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Calendar widget
Thanks Bernd, I stumbled on the same example and have been playing around with it. I ended up with this:
Code: Select all
on mouseUp
put the date into tToday
put shortDate2sqlDate(tToday) into pDate
put "0,0,234,234" into tProps["rect"]
put pDate into tProps["selectedDate"]
put "Red" into tProps["hiliteColor"]
put "Background" into tProps["hiliteStyle"]
popup widget "com.livecode.widget.calendar" at the mouseLoc with tProps
put it into pDate
answer pDate
end mouseUp
function shortDate2sqlDate pDate
// converts a LC short date (mm/dd/yy) to an SQL date (yyyy-mm-dd)
convert pDate to dateItems
set the itemDelimiter to comma
put item 1 to 3 of pDate into newSQLdate
replace comma with "-" in newSQLdate
return newSQLdate
end shortDate2sqlDate
Mark
- Attachments
-
- simple example.livecode.zip
- (3.21 KiB) Downloaded 212 times
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Calendar widget
Actually I was just being really lazy and planned to go back and fix it, but you beat me to itSparkOut wrote: ↑Wed Dec 09, 2020 8:39 amIt's just a shorthand way of checking the conditions without wrapping in "if...else...end if" constructions. There's only ever one value returned. With (thankfully) lazy evaluation you get "condition test failed...meh" and moving on to the next statement without importance whether the action on true was to return a value or put "cheesecake" in tOven. If the test passed, then the return statement is actioned, and that return exits the handler without and further statements being processed.
I am big on verbosity and almost always put full if...end if statements, but on certain occasions the single liner can be neat.


macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS