Timeline for What's the POSIX-compliant way to get the epoch timestamp in a shell?
Current License: CC BY-SA 4.0
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 21, 2022 at 16:14 | comment | added | ilkkachu | @done, that hardly matters, as faketime isn't a POSIX utility | |
| May 21, 2022 at 15:56 | comment | added | user232326 | @MechMK1 You do not need to be in 2107 to try that date. Try faketime 2107-01-01 ./script. | |
| May 19, 2022 at 20:49 | comment | added | MechMK1 | @IsaaC I'll be dead by then and then it's not my problem anymore. | |
| May 19, 2022 at 20:16 | comment | added | ilkkachu | @IsaaC, for obvious reasons, it'll be off by a day in 2101 already. I'm fine with that, and if anyone asks in 75 years, I'll be happy to fix it for them (usual force majeure exceptions applying). Other than that, if you have something in mind, you're free to post your findings in a comment. Not necessarily because I'd care, but in case you think someone else might. Better yet, if you think the existing answers on this question are lacking, post an answer of your own with a better solution. | |
| May 19, 2022 at 18:57 | comment | added | user232326 | Do you know what will be the output of your function on 01-01-2107 ? Is it correct ? | |
| May 19, 2022 at 16:19 | comment | added | doneal24 | That makes sense. While the function takes a while to puzzle out, it's still intuitively better than calling srand() in awk. | |
| May 19, 2022 at 16:12 | comment | added | ilkkachu | @doneal24, it should be ok, actually. (y-1969)/4 only gives 1 in 1973, the year after the first leap year after the epoch. Any leap day in the current year comes from %j. You can change the first line to e.g. eval "$(date -d "${1-now}" -u +'y=%Y j=%j h=%H m=%M s=%S')" and then test e.g. epochtime '2020-01-01 12:00' against date -u -d '2020-01-01 12:00' +%s. (With a date that has -d) | |
| May 19, 2022 at 16:08 | history | edited | ilkkachu | CC BY-SA 4.0 | added 458 characters in body |
| May 19, 2022 at 15:44 | comment | added | doneal24 | I think the shell function will be inconsistent if the current year is a leap year and you're calling it before 2/29. You add in the extra day in the year before the day actually occurs. | |
| May 19, 2022 at 15:26 | history | edited | ilkkachu | CC BY-SA 4.0 | dodge that zsh variable |
| May 19, 2022 at 14:20 | history | edited | ilkkachu | CC BY-SA 4.0 | added 549 characters in body |
| May 19, 2022 at 12:57 | history | edited | ilkkachu | CC BY-SA 4.0 | added 18 characters in body |
| May 19, 2022 at 12:41 | history | answered | ilkkachu | CC BY-SA 4.0 |