https://kotlinlang.org logo
#announcements
Title
# announcements
s

standinga

10/14/2019, 8:42 PM
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

Casey Brooks

10/14/2019, 8:46 PM
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

standinga

10/14/2019, 8:46 PM
this arent date timestamps
but av playback timestammps
y

Yago Lasse

10/14/2019, 8:48 PM
Why dont use nullable Long for this? Is there any specifc reason?
c

Casey Brooks

10/14/2019, 8:49 PM
Ah, got it. Nullable numbers would be my suggestion too, instead of using a specific “magic number” for “not set”
1
s

standinga

10/14/2019, 8:52 PM
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

Yago Lasse

10/14/2019, 8:53 PM
You can filter it in the set of the field. Whenever you receive no time or NaN, put it to null
s

standinga

10/14/2019, 8:54 PM
but then I can't distinguish between not set time or invalid time
these are different conditions in my case
y

Yago Lasse

10/14/2019, 8:54 PM
Sorry, now I get it
s

standinga

10/14/2019, 8:55 PM
I wasn't super clear about my requirements. My bad!
y

Yago Lasse

10/14/2019, 8:55 PM
Yeah, if you create a type that has the flags you need, i guess it would be easier
No problem!
s

standinga

10/14/2019, 8:57 PM
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

Yago Lasse

10/14/2019, 8:57 PM
😄
s

standinga

10/14/2019, 9:03 PM
The down side is I need to implement a couple of operators
y

Yago Lasse

10/14/2019, 9:06 PM
What if you extend Long (or Double)?
s

standinga

10/14/2019, 9:12 PM
great idea! 🙂
y

Yago Lasse

10/14/2019, 9:20 PM
🙂
6 Views