defano / wyldcard

A clone of Apple's HyperCard and HyperTalk scripting language.
https://github.com/defano/wyldcard/wiki
MIT License
117 stars 12 forks source link

tests using long dates fail (problems with locale settings) #85

Open rozek opened 2 years ago

rozek commented 2 years ago

First of all: thank you very much for this marvelous project!

I just started playing around with it:

ValueTest > testDateStyledCompare() FAILED
    org.opentest4j.AssertionFailedError at ValueTest.java:871

ValueTest > testIsADate() FAILED
    org.opentest4j.AssertionFailedError at ValueTest.java:727

both are related to "long date" formats, e.g.

assertTrue(new Value("Monday, January 1, 1985").isA(new Value("date")).booleanValue());     // Long date

and

assertEquals(1, new Value("Monday, January 1, 2000").compareTo(new Value("Monday, December 31, 1999"), SortStyle.DATE_TIME));

Long dates don't seem to be recognized.

I did not find the time to further investigate the problem, though, and, thus, may also be wrong.

My system is a Mac with german locale...

Edit: indeed, tests seem to fail because of the locale settings: (in HyperTalk) put "Sonntag, April 24, 2022" is a date displays true but put "Sunday, April 24, 2022" is a date displays false The question will now be: do you want dates to always be handled in english locale or to respect the system's locale setting?

Edit 2: as a hint: numbers are always parsed using the english locale (e.g., "1.23" is a number whereas "1,23" is not, although the german locale uses "," instead of "."). As a consequence, you may prefer to always handle dates in english locale...

With greetings from Germany,

Andreas Rozek

defano commented 2 years ago

Hi @rozek ,

Guten Abend, Deutschland. Grüße aus Chicago.

First, in case others run into this problem, you can execute ./gradlew generateBundle -x test to build the distributable with executing the unit tests.

You're quite right about the locale issue: I made no attempt to handle internationalization in the project. I think the right answer is that HyperTalk should respect the system's locale when parsing or producing both dates and numbers. Of course, this means that scripts are effectively non-portable between locales. Hmm...

Do you happen to know how HyperCard addressed this?

rozek commented 2 years ago

Good morning!

Trying both

in the message box of HyperCard 2.4.1 running within an Infinite Mac (macOS 8) gave true in both cases (I even changed "Date Formats" and "Time Formats" to "German" using the "Date & Time" control panel).

Although I haven't made systematic tests it seems as if HyperCard could handle dates and times in the english format regardless of the current locale...