Unix epoch date to Xojo date

I need to convert dates information from unix epoch date to Xojo date. According to my Goggle foo this should be

dim s as Integer = 1551222016 dim d as new Date d.TotalSeconds = s + 2082844800

After running the code I get 26.02.2019. The original data shows 24.02.2019. Did I miss something or is the bug in my data (MailTags)?

Your epoch val is correct on a Mac. According to this site your s value is Tuesday, February 26, 2019 11:00:16 PM in Posix time.

Must be Mailtags. I can’t get to it’s debug window anymore to check.

(Arghh, just updated MailSuite and all my tags are gone.)

EDIT

Whew, was just the plug-in Security pref had to be confirmed (for the umpteenth time).

Are you getting the Posix date from the email header? I couldn’t see one in the tagData.

This is what I use… seems to work OK…

dim d as new date
d.Month = 1
d.Day = 1
d.Year = 1970
d.Hour = 0 + d.GMTOffset
d.Minute = 0
d.Second = 0
d.TotalSeconds = d.TotalSeconds + val(TextField1.text)

where TextField1.text is the epoch number I want to convert.

The new MailTags data is a bit more convoluted. At the end of the mail emlx file there is a reference to a MailTags file which contains the tags proper.

The data in the emlx file for instance is:

[quote]com.smallcubed.tagIdentifier
MNGsgKMfQNby/9430qtycEwJmBQ5aYq[/quote]

This gives you an account identifier (MN etc). A numbered path (9430) from user/Library/Mail/SmallCubed/TagData and then the file with the identifier qt etc.

@James Meyer: your code gives me 27.02.2019.

Ist this perhaps a timezone problem?

Next try with a value of 1553209200. The wonderful website from Tanner says 21.03.2019, 23:00, which is 22.03.2019, 00 my timezone.

That makes sense since you’re +1 GMT. For giggles, here’s some example plist data that SmallCubed appends to the mail body on my Mac:

[code]<?xml version="1.0" encoding="UTF-8"?>

color 000000 com.smallcubed.tagIdentifier YUQhALYNYFCL/36127ze59xaALF_PGA conversation-id 9640 date-last-viewed 1552827154 date-received 1550035168 flags 25803619457 remote-id 401941 [/code]

I just add it because my tagIdentifier is different from yours. The dates are standard Posix though.

[quote=428955:@Beatrix Willius]I need to convert dates information from unix epoch date to Xojo date. According to my Goggle foo this should be

dim s as Integer = 1551222016 dim d as new Date d.TotalSeconds = s + 2082844800

After running the code I get 26.02.2019. The original data shows 24.02.2019. Did I miss something or is the bug in my data (MailTags)?[/quote]

“UNIX time” is based on a starting date of January 1, 1970. Here’s how I did it on Windows:

[code]Function Public Function UnixToDate(UnixTime As Double) as Date
// NOTE: THIS ROUTINE USES THE OLD FRAMEWORK DATE CLASS

// time value is in UNIX time (totalseconds) from 01/01/1970
// conversion is to set a Date object to 01/01/1970 and
// add the time value to the Date object’s totalseconds.
Dim tme As Double
Dim dte As New date(1970, 1, 1)
tme = UnixTime
tme = dte.TotalSeconds + tme
dte.TotalSeconds = tme
Return dte

End Function[/code]

make sure you set the correct tz offset as its based on Jan 1, 1970 UTC

There is even an example in the docs:

Of course, I now have to convert to the old date.

that is a challenge many of us have to do on regular basis. feel your pain.
–sb

This maybe of use:

https://forum.xojo.com/8429-date-value-to-unix-timestamp/0#p59601