hey! what would be the best way to implement NaN w...
# announcements
s
hey! what would be the best way to implement NaN with Long? I'm currently using Double.NaN to indicate invalid timestamps, but I'm leaning towards using milliseconds instead of seconds and using Long instead of Double. But I really like using NaN to indicate not set timestamp.
c
You’re probably better off using ISO-8601 formatted Strings for timestamps rather than millis, or any other number-type for representing timestamps. Java 8's LocalDate classes are really good for this.
s
this arent date timestamps
but av playback timestammps
y
Why dont use nullable Long for this? Is there any specifc reason?
c
Ah, got it. Nullable numbers would be my suggestion too, instead of using a specific “magic number” for “not set”
1
s
yeah, I thought about using nullable, but it's not exactly the same, because I have situations where I have not existing time, or time set to NaN
this is why I went for double (the other reason was I was porting my IOS code which uses apple CMTime, which operates on seconds, not milliseconds)
I guess I need to create a type for it.
y
You can filter it in the set of the field. Whenever you receive no time or NaN, put it to null
s
but then I can't distinguish between not set time or invalid time
these are different conditions in my case
y
Sorry, now I get it
s
I wasn't super clear about my requirements. My bad!
y
Yeah, if you create a type that has the flags you need, i guess it would be easier
No problem!
s
OK, thanks, actually when I described better my needs, I also realized I will benefit from having a type 🙂 Because I can also add computed properties returning seconds 🙂
Thanks again!
y
😄
s
The down side is I need to implement a couple of operators
y
What if you extend Long (or Double)?
s
great idea! 🙂
y
🙂