Weird? d = new date not current

I have a weird problem. All of a sudden, the simple code

Dim d as Date d = New Date is giving me date with a year 1904 (for instance)
Suggestions?

You’ll get better answers by providing more details when you ask questions

OS ?
What kind of project ? desktop ? console ? web ? ios ?
It helps to give a fuller explanation of the environment you’re seeing this occur in

Sorry. This is on a Mac desktop IDE. Not sure what else to explain.
The only thing that is unique is I added a Date property for comparison purposes. That makes no sense to add

Dim d as NEW Date
d = New Date

although I’d expect a “Nil Object” without the NEW

[quote=344540:@Arthur Gabhart]Sorry. This is on a Mac desktop IDE. Not sure what else to explain.
The only thing that is unique is I added a Date property for comparison purposes. That makes no sense to add[/quote]

Are you using the built in date class like your example suggests or have you subclassed Date, modified the constructor and forgot to call super?

[quote=344548:@Dave S] Dim d as NEW Date d = New Date
although I’d expect a “Nil Object” without the NEW[/quote]

You just created code which creates a date object and than replaces it with a new one.

the first new is not needed.

[quote=344537:@Arthur Gabhart]I have a weird problem. All of a sudden, the simple code

Dim d as Date d = New Date is giving me date with a year 1904 (for instance)
Suggestions?[/quote]
When Xojo starts to show freakish behaviour then it is time to restart the computer. Alternatively quit Xojo and clean out the cache by hand.

If this property is within scope of your code and it’s also called “d”, rename it because you will else end up using the localy created “d” only.

BTW: Before you use the Date Property, you init it using a

DatePropertyName = New Date

Correct?

All you need for the local “d” is a:

Dim d As New Date

Which creates indeed a New Date Object with the current Time.

Can you give us more information about the Date Property and the Code you are using for comparisson?

Here is the code as I wrote it and the Try is why I didn’t use a New immediately.

[quote]Dim dnOrg As Date
Try
dnOrg = fd.CreationDate
Catch err As NilObjectException
dnOrg = new Date
End Try[/quote]
I think the Markus Winter answer is the best answer. Unfortunately, I can’t find the cache. On a Mac, it should be under Library.Application Support.Xojo, but the XOJO doesn’t exist.

I’m going to guess that fd is not nil but doesn’t exist yet and that’s what’s causing this confusion.

The cache should be under ~/Library/Cache (in the user’s library, not the top library)

:wink:

Wayne. Yes. It may not exist. If it is the first run through, fd.exists is false.

Markus.
I have 2 folders: com.apple.AssetCache com.apple.iconservices.store

Neither mention XOJO, so I don’t think I should delete

~/Users/<UserName>/Library/Caches/Xojo

You can wipe everything within the Xojo Cache. But i doubt it’s related to your issue.

BTW:

Dim dnOrg As New Date Try dnOrg = fd.CreationDate Catch err As NilObjectException // Ignore Error End Try
should also work.

Made a short test and

[code]Dim f As FolderItem
f = GetFolderItem(SpecialFolder.Desktop.Child(“test.rtf”).NativePath)

Dim dnOrg As New Date

If f <> Nil And f.Exists Then

Try
dnOrg = f.CreationDate
Catch err As NilObjectException
// Ignore Error
End Try

End If

MsgBox dnOrg.AbbreviatedDate[/code]

Gives the expected result (the Date the File has been created).

What is the current dte on your macOS ?

Does it shows 1904 for the year ?

Under some circumstances, macOS display the default date (January 24, 1904 I think).

So, start checking the date in your Preferences --> Date (and set it to today isf this is 1904).

Then, fire Xojo without any reboot in between, and check what you get now.

And before you ask, you may have to change the inside battery that keeps the date and so many other properties alive.

NO, I do not talk about a Battery that allows your Portable to run some hours.

[quote=344574:@Sascha S]~/Users/<UserName>/Library/Caches/Xojo

You can wipe everything within the Xojo Cache. But i doubt it’s related to your issue.[/quote]
Thank you. I think I have problems with something more than XOJO. I hope it’s not the age of the MacBookPro Laptop - 2011
I checked the system date and tried to change it but the earliest I could get was 1969.
I ran DiskUtility, which said I have problems and should run it from Recovery.
Before I did that I deleted XOJO. Did the recovery and it cleaned things up.
Reinstalled XOJO.
I still don’t have the cache under ~/Users//Library/Caches/Xojo. In fact I don’t have a Library
Ran the program and therefore debugger. Checked first if it would generate a New Date that was in the first lines and it was current.
I ran it to a point after the suspect lines and it wasn’t right. It gave for a folderitem that didn’t exist the 1904 date.
Restarted crashed when I got to the Try of this line and it crashed.

You have a library. It is just invisible to prevent users who have no clue from mucking it up. In the finder click on the menu “go to”, hold the option key, and the menu item library is shown.

A folderitem that doesnt exist wont have a current date
It will have a date initialized as if the totalseconds was 0