I decided to try to change it to the new format (times about sixty)
I immediately get the analyzer error "There is more than one method with this name but this does not match any of the available signatures.
The code worked before, so it must be something simple.
Thats really redundant though
DateTime.Now creates a temporary
And then the Datetime constructor creates a new one that is eventually retained
And the original that datetime.now created is just thrown away
Either way not having a 0 param constructor that just does what DateTime.Now does makes things more verbose - which folks disliked about the Xojo framework ¯\(?)/¯
Totally agree about the double allocate waste I was jut proving an alternate method, I’d do it the way you suggested but I guess using empty constructor as an allocate to Now might be a waste/overhead/confusing too.
If it’s an empty allocate (no param constructor) it should really be the lowest possible value (1,1,1) rather than Now, if it were Now and you didn’t want it to be Now you’re introducing the overhead of allocating the current date/time even though you’re not interested in it which most would probably do as they would’t know/learn any better because it just allowed them to do it that way in the first place. From a technical perspective its neater the way it is now, but usability wise, I’m not so sure. I guess people will have to adapt, its now more inline with other languages.
[quote=483585:@]Totally agree about the double allocate waste I was jut proving an alternate method, I’d do it the way you suggested but I guess using empty constructor as an allocate to Now might be a waste/overhead/confusing too.
[/quote]
wouldn’t be wasteful since only one object would ever be created and initialized
as for “unclear” well … that remains to be seen
I’m not sure that my first incantation is that much clearer to anyone
Which is why they have the other constructors if what you wanted isnt “now”
But - my argument FOR the no param constructor rests on considering what existing users expect from similar old code and trying to do something similar with API 2
We know thats not a priority
[/quote]
I guess people will have to adapt, its now more inline with other languages.[/quote]
much like C#
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
DateTime localDate = DateTime.Now;
DateTime utcDate = DateTime.UtcNow;
wasteful only in that someone might not know any better, new it and have it then go through all the init and allocates now then uses it for something complete different thus wasting all the now allocation. As it is now you have to tell it what you want.
Yes, I was thinking of c# but didn’t want to reference it
[quote=483599:@Arthur Gabhart]I kinda figured that, but it doesn’t make sense. There also is no clear example.
There is nothing on the page with a “Dim”.
So. My code should read:
Dim d12Dte As DateTime = DateTime.Now
They introduced Var that works like Dim. They are pushing Var now on the documents (for Xojo2019r2.1 and later).
On the first you are using a value that you know (Seconds), the other doesn’t have that value so it is not clear what you want to do. Of course, Xojo can fix that and make it work as expected.
You can have consistency if you need to provide seconds to create a date
Var SomeDate As New DateTime(Seconds)
if you have the seconds that you want to convert for a date using the current time zone, and if you don’t you can do
Var SomeDate As New DateTime(DateTime.Now.SecondsFrom1970)
It is clear for me and easy to understand. I guess because I’m relatively new to Xojo and programming.
You are correct about Var, but I have no idea when. I have a 2011 reference and Var isn’t listed. Vartype is.
It’d be nice if the manual would show that. I’m leaving it as “that” because there are a few ways it could be improved.
[quote=483607:@Alberto DePoo]On the first you are using a value that you know (Seconds), the other doesn’t have that value so it is not clear what you want to do. Of course, Xojo can fix that and make it work as expected.
You can have consistency if you need to provide seconds to create a date
Var SomeDate As New DateTime(Seconds)
if you have the seconds that you want to convert for a date using the current time zone, and if you don’t you can do
Var SomeDate As New DateTime(DateTime.Now.SecondsFrom1970)
It is clear for me and easy to understand. I guess because I’m relatively new to Xojo and programming.[/quote]
If the blank constructor is not clear, why any constructor at all? Why not Var SomeDate As DateTime = DateTime.FromSeconds(Seconds, TimeZone)? If you want the clarity of shared methods, use shared methods. If you want the convenience of constructors, use constructors. But it is inconsistent to use both.
If I have to guess, DateTime code is coming from Xojo.Core.Date, there is no blank constructor for Xojo.Core.Date either, but there is Now as a Shared Method.
I created a couple of private requests for DateTime (back in August) to make Time Zone optional when supplying seconds to the constructor and to add a Time Zone option when using DateTime.FromString (if you see Xojo.Core.Date those options are not available), both were implemented.
Maybe if someone file a feature request for them to add a blank constructor for DateTime, because it makes sense to have it, they will deliver it. I can do it if you want, unless there is already a FC about this.