Xojo.Core.Date question

I’m playing around Xojo.Core.Date and its Timezone property. So I placed this in a button action to test some stuff out:

[code]Dim laTZ As New Xojo.Core.TimeZone(“PST”)

Dim laDate As New Xojo.Core.Date(Xojo.Core.Date.Now.Year, _
Xojo.Core.Date.Now.Month, _
Xojo.Core.Date.Now.Day, _
Xojo.Core.Date.Now.Hour, _
Xojo.Core.Date.Now.Minute, laTZ)

MsgBox laDate.ToText(laTZ, Xojo.Core.Date.FormatStyles.Long, Xojo.Core.Date.FormatStyles.Long)[/code]

When I attempt to compile the above, I’m told that “there is more than one item with this name and it’s not clear to which this refers.” The entire final MsgBox line is highlighted.

If I change that final line to

MsgBox laDate.ToText(laTZ, laDate.FormatStyles.Long, laDate.FormatStyles.Long)

I’m told "type “Xojo.Core.Date” has no member named “FormatStyles.”

My reading online only shows people using code of the first format above, but I can’t seem to get that to work. I’ve tried a bunch of other changes to try to get that to work, but all to no avail.

In my experience, with the way you are using msgbox as a statement, sometimes it pays to assign a function to a string variable on a previous line and on the next line make the message box display that string variable.

I note that in the language reference, message box syntax is expressed as a function msgbox("hello world") and returns a value to your calling code in desktop apps but not Web and Console apps.

Could it be that you are passing TEXT to the msgbox where it is expecting a STRING?

never understood why this is or should be a distinction

[quote=414040:@Dave S]Could it be that you are passing TEXT to the msgbox where it is expecting a STRING?

never understood why this is or should be a distinction[/quote]
I’ve always found I could pass Text to MsgBox. But I also tried converting to String on a separate line and passing that String variable to MsgBox (as Eric suggested), and that yielded the same error message, highlighting the entire FormatStyles line.

Had another look at this: Seems you are passing a TimeZone object when the ToText method expects to be passed a Locale object.

[quote]Could it be that you are passing TEXT to the msgbox where it is expecting a STRING?

never understood why this is or should be a distinction[/quote]
ToText object provides access to a bunch of methods operating on text characters, which to support different languages may be encoded using more than one byte per character, which the programmer doesn’t have to worry about.

Yeah, I already tried that and was told Locale doesn’t even exist when testing running this:

MsgBox laDate.ToText(Locale.Current, Xojo.Core.Date.FormatStyles.Long, Xojo.Core.Date.FormatStyles.Long)

Ah, but this works:

MsgBox laDate.ToText(Xojo.Core.Locale.Current, Xojo.Core.Date.FormatStyles.Long, Xojo.Core.Date.FormatStyles.Long)

I needed Xojo.Core in there, prepending Locale. Forgot that. Thanks, Eric.

I do notice that Xojo throws a Bad Timezone exception with this, however:

Dim laTZ As New Xojo.Core.TimeZone("PDT")

Maybe because I’m running 2017r3?

The docs say to refer to https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for the list of zone names. PDT isn’t in there.

Thanks, Scott. I’m finding this Timezone thing getting confusing (and perhaps unreliable) and think I’ll just stick with GMTOffset values whenever this is practical. In my current app, this is very doable.

Assuming laTZ stands for Los Angeles time zone, you could use America/Los_Angeles instead of PDT.

And I can safely assume that in the following code

Dim laTZ As New Xojo.Core.TimeZone("America/Los_Angeles") Dim nyTZ As New Xojo.Core.TimeZone("America/New_York") Dim nowDate As Xojo.Core.Date = Xojo.Core.Date.Now Dim laDate As New Xojo.Core.Date(nowDate.SecondsFrom1970, laTZ) Dim nyDate As New Xojo.Core.Date(nowDate.SecondsFrom1970, nyTZ)

not only will laDate and nyDate be 3 hours apart, they also will reflect whether or not Daylight Savings Time is active? That is, I can rely on Xojo to know if DST is active in this or that timezone and report the correct time accordingly?

Bugs and local law changes not withstanding, yes, Xojo says it handles savings time:

https://blog.xojo.com/2017/11/04/get-better-dates-with-the-new-xojo-framework/

Well, well. That is impressive. I’ve never strayed from Classic Date, and just the last 24 hours stated experimenting with the Xojo.Core.Date code to see how to use Timezones. Thanks, Scott.