I’m working on a calendar application (pictured below) that has a vertical view of each week. Currently, I’m finding the current day of the week using using date.wday, then incrementing and decrementing the surrounding dates accordingly. However, this does not work when the week spans two months, for example, Sunday June 1st would be represented as Sunday May 32nd.
Here is the code if today is a Thursday:
if(date.wday == 5) then local monDate = display.newText( date.day - 3, 25, ((display.contentHeight/7)), "Helvetica", 16 ) monDate:setTextColor(0, 0, 0, 255) group:insert( monDate ) local tueDate = display.newText( date.day - 2, 25, ((display.contentHeight/7) \*2), "Helvetica", 16 ) tueDate:setTextColor(0, 0, 0, 255) group:insert( tueDate ) local wedDate = display.newText( date.day - 1, 25, ((display.contentHeight/7) \*3), "Helvetica", 16 ) wedDate:setTextColor(0, 0, 0, 255) group:insert( wedDate ) local thuDate = display.newText( date.day, 25, ((display.contentHeight/7) \*4), "Helvetica", 16 ) thuDate:setTextColor(0, 0, 0, 255) group:insert( thuDate ) local friDate = display.newText( date.day + 1, 25, ((display.contentHeight/7) \* 5), "Helvetica", 16 ) friDate:setTextColor(0, 0, 0, 255) group:insert( friDate ) local wkndDate = display.newText( date.day + 2 .. '/' .. date.day + 3, 20, ((display.contentHeight/7) \*6), "Helvetica", 16 ) wkndDate:setTextColor(0, 0, 0, 255) group:insert( wkndDate ) end
And here is what it looks like:
Any advice would be appreciated!