xojo.core.date maths

hi,

Im trying to get the Monday and friday of the week that a date is in by adding a dateinterval to the date.
when these overlap a month/year change I expected it to sort out the months and years for me, but it doesn’t.

am i missing something obvious?

Maybe show us a little code on how you’re trying to do it?

Hi Bob,

This is my code.

[code] using xojo.core

//the day of the week, with 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday, 7 = Saturday.
Dim day As Integer = Date.Now.DayOfWeek

minDate = Date.Now
maxdate = Date.Now

Dim Mdi As New DateInterval
Dim Fdi as new DateInterval

select case day
case 1
Mdi.days = 1
fdi.Days = 5
case 2
mdi.days = 0
fdi.Days = 4
case 3
mdi.days = -1
fdi.Days = 3
case 4
mdi.days = -2
fdi.Days = 2
case 5
mdi.days = -3
fdi.Days = 1
case 6
mdi.days = -4
fdi.Days = 0
case 7
mdi.days = -5
fdi.Days = -1
end select

mindate = Date.Now + mdi
maxdate = date.now + fdi

lblDates.text = "F : " + minDate.ToText(mLocale, Date.FormatStyles.Short, Date.FormatStyles.None) + EndOfLine + "T : " + maxDate.ToText(mLocale, Date.FormatStyles.Short, Date.FormatStyles.None)[/code]

Off the top of my head, something like this should get you started (not sure if it is proper XOJO date code for manipulating dates, but it should get you in the correct direction):

minDate = Date.Now - (Date.Now.DayOfWeek - 2)
maxDate = minDate + 4

Hi @Mark Walsh

I was trying to use the dateinterval object in the new framework, to see how it works.
Is your code new framework or classic?

the code is working for me,

launching with current date I have:
F : 29/06/15
T : 03/07/15

and launching with, say “2015-12-31” as a date to overlap the year:
F : 28/12/15
T : 01/01/16

obviously, my locale is italian, so my dates are dd/mm/yy

Seems to work fine here

well, thats very weird then!

with my clock set at today i’m getting

F : 29/06/2015
T : 03/06/2015

which is fine of course.

with my clock set at 30/12/2014 i’m getting

F : 29/12/2014
T :02/12/2014

[quote=197885:@Russ Lunn]Hi @Mark Walsh

I was trying to use the dateinterval object in the new framework, to see how it works.
Is your code new framework or classic?[/quote]
Probably neither, I was attempting to show that there’s a short and simple way to calculate the dates without using the ‘Case’ statement.

@Norman Palardy unless i’m doing something really stupid (which has been known) this isn’t working right

adding 3 days to today should get me 03/07/2015 but i’m getting 03/06/2015

30-Jun-2015 is today
3 days from now is 03-Jul-2015

assuming you are doing this?

dim today as new date
today.day=today.day+3

[quote=197943:@Russ Lunn]@Norman Palardy unless i’m doing something really stupid (which has been known) this isn’t working right

adding 3 days to today should get me 03/07/2015 but i’m getting 03/06/2015[/quote]
I’m getting the same results. DateInterval doesn’t seem to be working correctly. It didn’t increment the month when the day rolled over.

Hi Dave,

I’m trying to get to grips with the new framework, mainly because Linux cgi won’t use locale specific date formatting, but also because it’s the future.

I’m using dateinterval and xojo.core.date as per the docs.
Norman says it works for him but I’m still having issues

What platform are you testing on?

Well, I’m on Windows 8.1 64bit. Latest xojo

I tried a web app and a desktop one

just tried a desktop app on OSX and it appears to work there.

Tested on Windows 7, Xojo 2015r1 (clicked the wrong icon).

I just confirmed this on the latest Alpha, Windows 7.

OK, I can confirm that it seems to work on Mac, and not on Windows

if I run the original code on Mac I get correctly:
F : 29/06/15
T : 03/07/15

if I run it on windows 8 I get:
F : 30/07/15
T : 03/07/15

if I compile on Mac and run on Windows I got the incorrect values, too

it would appear that Feedback Case #37413 is not fixed and verified, since @Tim H
has confirmed it isn’t working on 2015r1

@Norman P Not sure of the procedure here…
do I add to that case (which is closed and verified) or Open a new case?