I'm doing some follow-up on the situation describe...
# adobe
a
I'm doing some follow-up on the situation described in this Stack Overflow question: https://stackoverflow.com/q/72345620/894061. Consider this code...
Copy code
setTimeZone("Asia/Karachi")

// control
dlsSwitchOver = createDateTime(2022,6,1,0,0,0)
writeOutput(dlsSwitchOver.dateTimeFormat("yyyy-mm-dd HH:nn:ss")) // Both CF and Lucee: 2022-06-01 00:00:00

writeOutput("<hr>")

// experiment
try {
    dlsSwitchOver = createDateTime(2008,6,1,0,0,0)
    writeOutput(dlsSwitchOver.dateTimeFormat("yyyy-mm-dd HH:nn:ss")) // Lucee: 2008-06-01 01:00:00
} catch (any e) {
    writeOutput(e.message) // CF: Date value passed to date function createDateTime is unspecified or invalid.
}
Note the behavioural difference between CF2021 and Lucee there. Lucee goes "yeah, OK, you say
2008-06-01 00:00:00
, but on that day the clocks go forward right then, so it's actually
2008-06-01 01:00:00
". CF goes "yeah, OK, you say
2008-06-01 00:00:00
, but on that day the clocks go forward right then, so I'm gonna error".
Both seem reasonable in a way, but the behavioural difference is not good. Initially I side with CF from a perspective of "garbage in / garbage out", but I checked what Java does in an analogous situation, and Java does what Lucee does. This example is runnable on CF (but not trycf.com unfortunately, because reasons):
Copy code
testZonedDateTime = java {

    import java.time.format.DateTimeFormatter;
    import java.time.ZonedDateTime;
    import java.time.ZoneId;

    public class TestZonedDateTime {

        public String getControlDateTimeAsString() { // 2022-06-01 00:00:00
            return getFormatedZonedDateTime(2022);
        }

        public String getDaylightSavingSwitchoverDateTimeAsString() { // 2008-06-01 00:00:00
            return getFormatedZonedDateTime(2008);
        }

        private String getFormatedZonedDateTime(int year) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");

            ZonedDateTime dlsChangeOverTime = ZonedDateTime.of(year, 6, 1, 0, 0, 0, 0, ZoneId.of("Asia/Karachi"));

            return formatter.format(dlsChangeOverTime);
        }
    }
}

writeOutput(testZonedDateTime.getControlDateTimeAsString() & "<br>") // 2022-06-01 00:00:00 NB: hour is **0**
writeOutput(testZonedDateTime.getDaylightSavingSwitchoverDateTimeAsString() & "<br>") // 2008-06-01 01:00:00 NB: hour is **1**
I also tested PHP, and it behaves the same as Java and Lucee. I got a mate to test C++ and it also is clever enough to work out what the code is asking for. My conclusion is that this is a bug in CF. Someone on that Stack Overflow raised a ticket for it (https://tracker.adobe.com/#/view/CF-4213572), but the underlying cause is slightly obscured by their example. Initially I piped-up saying "not a bug", but... I've changed my mind now. I'm left wondering if there is any legit basis for the current CF behaviour to not be considered a bug?
1
👍🏾 1
m
Time zones are... fun. I think basically it is picking the smaller of two bags of junk. I understand why CF errors, and it is TECHNICALLY correct, but approaching this from the point of view of Developer Experience (TM) the other languages have the better of the argument, as they "handle" the issue more smoothly. Just erroring out is kind of not a nice way to handle this, and while I get that it is an edge case, I think we could be smoother about it.
👍 1