0

The date is approaching (in fact, 2022-01-08), when Unix time turns 19000-days old. Currently, there is a way (namely, %s) to display Unix second in dates, but there seem to be no way to display Unix day in date formatting. How does one display Unix day in dates? If not possible, then how to introduce new date formatting symbol (%?) symbol for it?

Why?

  1. Epoch date is easy to compute just dividing Unix seconds / 86400, and works well as natural decimal time, where:

    1 dYear = 1000 days, 1 dMonth = 100 days, 1 dWeek = 10 days,
    1 dHour = 0.1 days, 1 dMinute = 0.001 days, 1 dSecond = 0.00001 days.

  2. Unix day digits, unlike Unix second's digits, approximate lengths of ordinary concepts of time with less than 1 order of magnitude, thus work well as decimal time and date, where:

For example, now is Unix day = 18993.94830052069 means:

18993.94830052069
 \ \\\ \ \ 30.052069 th decimal second
  \ \\\ \ 48 th decimal minute
   \ \\\  9 th decimal hour
    \ \\ 3 rd day of week
     \ \ 9 th decimal week
      \  9 th decimal month
        18 th decimal year

Unix day, interpreted this way, has the benefit of convenience of use as natural support for decimal time, so some people use it and need it.

Ultimately, I'd like to know a path for incorporating this display of time as one of the supported ways of displaying date and time in *nix systems.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Mindey I.
  • 29
  • 1
  • 6
  • 1
    I do not understand your question. Why is it in __bold__? `there is a way (namely, %s)` What do you mean by "way"? What "way" exactly? Are you referring that `date` utility takes an argument `+%s` and with that argument __that utility__ outputs number of seconds since epoch? `Unix second in dates` "dates" is not an unit of measurement, unix seconds are in seconds, not "in dates". Could you clarify that sentence? `how to introduce new date formatting symbol (%?` "introduce" - where? To what? To whom? To me? – KamilCuk Jan 02 '22 at 00:02
  • @KamilCuk -- yes, I mean the date utility -- `date +%s` displays the Unix second, is there a way to display Unix day with it? `date +%???`. For example, `date +"%Y-%m-%d [%w] #%j T %T Z"` is the traditional date, it works well, but what would be the symbol for Unix day (preferably, up to 5 decimal digits, or custom number of digits if possible). – Mindey I. Jan 02 '22 at 00:05
  • 2
    `Unix day with it?` What is an "unix day"? Number of seconds since epoch divided by `86400`? – KamilCuk Jan 02 '22 at 00:06
  • "write program" -- agree, and done that, but evolving the `date` utility, creating a PR to it (if it is not yet supported) looks like the right way. And, P.S.: removed bold from question. – Mindey I. Jan 02 '22 at 00:09
  • `Unix day` = Number of seconds since epoch divided by `86400`? -- Yes, exactly. – Mindey I. Jan 02 '22 at 00:10
  • The display of seconds since 1970 isn't included on a whim, it is a common way of storing and processing timestamps. Other than there being a cute looking value coming up, do you have any actual use case for your date format? Unix time is useful because a single 32- or 64-bit integer can represent a wide range of dates and times to a 1 second precision, which is sufficient for most purposes. – IMSoP Jan 02 '22 at 00:18
  • // Other than there being a cute looking value coming up, do you have any actual use case for your date format? Yes, it's the the most straightforward way to bring support of [decimal time](https://en.wikipedia.org/wiki/Decimal_time) into systems at the display level. Unix seconds is great as they are basis for dates already. – Mindey I. Jan 02 '22 at 00:22
  • Ok, so basically, I start understanding that the answer is probably along the lines that I should `git clone git://git.sv.gnu.org/coreutils` and edit `src/date.c` it in, then build, test it, make a PR, get it accepted upstream. I'll look into this. – Mindey I. Jan 02 '22 at 00:22
  • 2
    Have you thought about leap seconds? (others have) – wildplasser Jan 02 '22 at 01:08
  • Since `Unix day` would be deterministically derived unit from `Unix second`, this time would inherit all the imperfections (such as "some timestamps are not real times, and some timestamps are not unique times") as well... – Mindey I. Jan 02 '22 at 01:23

1 Answers1

1

date +%s displays the Unix second, is there a way to display Unix day with it?

No, it is not possible.

how to introduce new date formatting symbol (%?) symbol for it?

Download the sources of the date utility implementation that you are using and patch it with a custom modifier. GNU date (if you are using GNU date...) is part of GNU coretuils, see https://www.gnu.org/software/coreutils/ . Date utility follows POSIX specification.

I do not have ever encountered any need for a "number of days since epoch with fractional part" format. I do not believe it has any practical usage. I do not believe such a formatting specifier should be added to date. I see no value in it over "number of seconds since epoch with fractional part" (date +%s.%N), it's just a change of unit. I wouldn't want those hard-working GNU developers that are giving their work to the world for free, for them to spend time on something that has no practical application. I would like them to they spent their time with their families or on other more important things. As such, I encourage you to not take developers time, unless you can strongly prove that the community requires such a formatting specifier for practical reasons.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • Thanks, [KamilCuk], got it. It probably means that will have to bring in proposals to [POSIX.1-2017, IEEE Std 1003.1™-2017](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/#:~:text=Base%20Definitions,-Introduction&text=POSIX.&text=Specifications%2C%20Issue%207.-,POSIX.,POSIX.) before updating the code, and look into this thing. Regarding the price of developers -- it's just one value to return in formatting (unix seconds/86400 trimmed to 5 places after decimal point would do), nothing of the sort of development requiring to support various fractions like in Gregorian calendar. – Mindey I. Jan 02 '22 at 00:32
  • Based on `date +%s.%N` example, I conclude that perhaps the better approach to `Unix day` thus would be to introduce extra 2 formatting symbols - one representing integer of days, another, the integer representing fractional part of day. – Mindey I. Jan 02 '22 at 00:44
  • 2
    The general concept of "fractional days since epoch" is not unheard of; [Julian date](https://en.wikipedia.org/wiki/Julian_day) is commonly used in astronomy and other fields. Just a different choice of epoch. – Nate Eldredge Jan 02 '22 at 03:07
  • Yes, yes, and some people use it, and need, related article: https://stackoverflow.com/questions/67225353/what-do-you-call-the-number-of-days-since-the-unix-epoch – Mindey I. Jan 02 '22 at 09:38
  • Note: it concerns only the [nstrftime.c](https://github.com/coreutils/gnulib/blob/master/lib/nstrftime.c), which is used by [fprintftime.c](https://github.com/coreutils/gnulib/blob/master/lib/fprintftime.c), which is then used by `date` util, which is called [there](https://github.com/coreutils/coreutils/blob/master/src/date.c#L668), by providing "format" parameter. Would suffice adding bespoke format parameter. – Mindey I. Aug 21 '22 at 09:07