Re: [PATCH v1 1/4] lib/vsprintf: Print time64_t in human readable format

From: Alexandre Belloni
Date: Mon Sep 30 2019 - 17:20:27 EST


On 26/07/2019 16:20:37+0300, Andy Shevchenko wrote:
> On Thu, Jan 10, 2019 at 10:58:58PM +0100, Alexandre Belloni wrote:
> > On 08/01/2019 16:25:28+0100, Petr Mladek wrote:
> > > On Fri 2019-01-04 21:30:06, Andy Shevchenko wrote:
> > > > There are users which print time and date represented by content of
> > > > time64_t type in human readable format.
> > > >
> > > > Instead of open coding that each time introduce %ptT[dt][r] specifier.
> > > >
> > > > Few test cases for %ptT specifier has been added as well.
>
> > > > +void time64_to_rtc_time(time64_t time, struct rtc_time *rtc_time)
> > > > +{
> > > > +#ifdef CONFIG_RTC_LIB
> > > > + rtc_time64_to_tm(time, rtc_time);
>
> > > I wonder if the conversion between struct tm and rtc_time
> > > might be useful in general.
> > >
> > > It might make sense to de-duplicate time64_to_tm() and
> > > rtc_time64_to_tm() implementations.
>
> > Looking at 57f1f0874f42, this seemed to be the plan at the time
> > time_to_tm was introduced but this was never done. Seeing that tm and
> > rtc_time are quite similar, we could probably always use time64_to_tm as
> > it is more accurate than rtc_time64_to_tm as the latter assumes a
> > specific year range.
>
> So, do I understand correctly that dropping #ifdef along with
> rtc_time64_to_tm() call is sufficient for now?
>

I'd be fine with that.

> > Maybe be rtc_str should take a struct tm instead of an rtc_time so
> > time64_to_rtc_time always uses time64_to_tm.
>
> Because this one, while sounding plausible, maybe too invasive on current
> state of affairs.
>

Well, if the kernel struct tm had an int tm_year instead of long
tm_year, then you could simply cast a struct rtc_time to a struct tm.
I'm not sure was was the rationale to have a long, especially since
userspace has an int.


--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com