18
galena
1y

Yall ever cast a bool to a dateTime?

Fucking structured text never ceases to amaze me!

Comments
  • 8
    false == 1970-01-01
    true == 9999-12-31

    🤔
  • 3
    @SuspiciousBug If it's Unix time, how do you get the second? If it's a struct of ints, how do you get the first?
  • 2
    @lorentz you probably have to cast back to bool and then to int I guess
  • 6
    I will be writing a compiler for structured text soon. Looks like I'm in for a world of fun 👁👄👁
  • 8
    Hey guys what's going on in he-
  • 3
    Computers cast bools to everything else.
  • 10
    false = 0 = Jan 1st 1970 00:00:00
    true = 1 = Jan 1st 1970 00:00:01

    What else?
  • 9
    Never did that. But I occasionally scratch my bools from time to time.
  • 15
    - What time is it?
    - Yes.
  • 1
    @horus ah, yes! That makes more sense lol
  • 6
    Just don’t :)

    If its even possible in what ever language you are using it will depend on how the datetime is stored under the hood, and we should generally not build code that depends on that since such code will be harder to maintain and are more likely to break upon new versions of the compiler.

    C famously have such undefined cases where different compilers get different results due to different assumptions and since the language does not enforce one specific way, both are right or wrong depending on your point of view.

    Js also has a lot of strange casts that I also try to avoid since the day you need to refactor it you will need to find every such “clever” cast and change it ;)
  • 4
    Deep down, all data is binary, so you can cast anything to anything (if your language allows it).
Add Comment