About dates (today+1 day)

Is there a wat to get MyDate +1 day in one line of code ?

I have been creating a new date with totalseconds = mydate+86400

Is there a one line solution ?

Thanks

dim d as Xojo.Core.Date = Xojo.Core.Date.Now + new Xojo.Core.Dateinterval(0,0,1)

you have to do THAT much in the “new” framework?

it used to be “simple”

Dim d as new Date
d.day=d.day+1

[quote=331325:@Dave S]you have to do THAT much in the “new” framework?

it used to be “simple”

Dim d as new Date d.day=d.day+1 [/quote]

Using Xojo.Core dim d as Date = Date.Now + new Dateinterval(1,1,1,1,1,1,1)

Easy is all relative, how easy can you do the above?

[quote=331326:@JulianS]Using Xojo.Core
dim d as Date = Date.Now + new Dateinterval(1,1,1,1,1,1,1)[/quote]
Shouldn’t that be:

dim d as Date = Date.Now + new Dateinterval(0,0,1,0,0,0,0)

[quote=331327:@Eli Ott]Shouldn’t that be:

dim d as Date = Date.Now + new Dateinterval(0,0,1,0,0,0,0)

Nope, I was responding to Dave there. My response to Roman is up above.

+1

[quote=331325:@Dave S]it used to be “simple”

Dim d as new Date d.day=d.day+1 [/quote]
But that’s not a one line solution.

no. no it not… but the “one line solution” is a violation of my “4 rules”

First Rule:
The code must be READABLE
Preferable with copious comments, but the code should be as close to self explanatory as possible, this is not only for yourself, but for anyone else who in the future may have to work with the code.

Second Rule:
The code must be MAINTAINABLE
This should be done in such a way as to provide the minimum conflict with the First Rule.

Third Rule:
The code must be SCALABLE
This should be done in such a way as to provide the minimum conflict with the First or Second Rule.

Fourth Rule:
The code should be EFFICIENT
This should be done in such a way as to provide the minimum conflict with all other rules.

and there I will leave it… Personally I see no reason at all for the obsfucated (my opinion) structure of the new framework (and don’t but the rationale that “it was required to support iOS”…

[quote=331343:@Dave S]The code must be READABLE
Preferable with copious comments, but the code should be as close to self explanatory as possible, this is not only for yourself, but for anyone else who in the future may have to work with the code.[/quote]
My personal gripe with this construct is that you have an object of type Xojo.Core.Date and via an overloaded add function adds an object of type Xojo.Core.DateInterval to get a Xojo.Core.Date back.

I am not used to this way of mixing an apple with a banana to get an different apple back.

[quote=331347:@Mattias Sandström]My personal gripe with this construct is that you have an object of type Xojo.Core.Date and via an overloaded add function adds an object of type Xojo.Core.DateInterval to get a Xojo.Core.Date back.

I am not used to this way of mixing an apple with a banana to get an different apple back.[/quote]
Huh??? At no time did my “two line” example make reference to the “new framework”… so I am missing the “apple/banana” reference

The main difference between date and Xojo.Core.Date is that the latter is immutable.

when you do: (classic framework)
d.day=d.day+1
you are changing the original object
Since d is an object, this should be obvious. But too many developers used it as if it were another object.
Moreover, for the same reason as basis, if they don’t use the right order on changing the date parts they could get unexpected results.

the new framework date object solves this problems since it’s immutable and the dateInterval operation is atomic and done in the right way.
newDate=OriginalDate+new dateInterval(0,0,1)
now NewDate is a new object, it’s not the same with different parts.

Yes there is more code to write, but you can easily create extensions like:
function tomorrow as Xojo.Core.Date
return Xojo.Core.Date.now+new DateInterval(0, 0, 1)
end function
or
function nextDay(extends d as Xojo.Core.Date) as Xojo.Core.Date
return d+new DateInterval(0, 0, 1)
end function

Thanks a lot. This has been very educative.

[quote=331354:@Antonio Rinaldi]function nextDay(extends d as Xojo.Core.Date) as Xojo.Core.Date
return d+new DateInterval(0, 0, 1)
end function[/quote]

how do i use the NextDay function??

Create a module, maybe call it dateextension, add a using clause to it with the content Xojo.Core, and then add a method:

Public Function NextDay(extends d as date) as date return d + new DateInterval(0,0,1) End Function

Now you can everywhere you have a xojo.core.date write something like

mydate.Nextday …

DateInterval also helps you avoid other craziness with the new framework, like feedback case # 46855 which shows how you can create a negative date (like December -2, 2017) or time (-5 o’clock).

So, wait, are there pros and cons to using the classic vs new framework? Overall? With dates? OR is the new framework hands down the best choice? I’ve got a heavily date/calendar dependant project and now wonder if I need/should rewrite it before going on…

I have an application that is quite calendar-oriented. It is all on the classic framework and it works well. If I were to write it today, I would choose the new framework if only to have the ability to port it to IOS and future platforms, which presumably will not be supported by the classic framework. It is not so much a question of better or worse, but right tool for the target platform.

Oh, that’s a good point. I’d like to transfer many of the project’s abilities to iOS at a later date (no pun intended!), so that’s a good point to consider.

I think that kind makes my point