Re:I'm “still afraid to use spaces in file names” years old
by globular-toast on Thursday November 11, 2021 @10:56AM
(#29189323)
This goes for most instances of user input. Timestamps is the other common one people get wrong. I've even seen programs that pass around timestamps as strings in multiple formats and as integers (Unix time).
[ Parent
| on HN ]
Re:I'm “still afraid to use spaces in file names” years old
by aqfamnzc on Thursday November 11, 2021 @11:16AM
(#29189608)
As a programming noob, I'm wondering what would be the better way to pass or return a unix time value as opposed to an integer?
Re:I'm “still afraid to use spaces in file names” years old
by mleonhard on Thursday November 11, 2021 @06:44PM
(#29194729)
If you need to keep the timezone with it, then use an ISO8601 [0] string: "2021-11-11T15:32:35-07:00".
Otherwise, use an integer unix timestamp, the number of seconds since 1970-01-01T00:00:00Z: 1636673555. Use an unsigned 32-bit integer or a 64-bit integer to avoid the 2038 problem [1]. JSON's maximum safe integer value is a signed 53-bit integer, so if you're using HTTP JSON RPC, you'll have to check for overflow.
[0] https://en.wikipedia.org/wiki/ISO_8601
[1] https://en.wikipedia.org/wiki/Year_2038_problem
[2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re:I'm “still afraid to use spaces in file names” years old
by globular-toast on Friday November 12, 2021 @04:33AM
(#29197628)
ISO8601 is a serialisation format. You wouldn't want to use it in internal function calls simply for performance reasons. You also wouldn't want to pass it around as just a "string" type. I think the question was asking about internal function calls. For external data interchange, ISO8601 is the only sane option and deals with all known timezone and leap second bollocks.
Re:I'm “still afraid to use spaces in file names” years old
by globular-toast on Thursday November 11, 2021 @11:25AM
(#29189741)
Depends on the language but most high-level languages have a timestamp or datetime abstraction which you should be using.