Re: [hackers] [sbase][Patch] date: add date/time setting capability

From: Michael Forney <mforney_AT_mforney.org>
Date: Tue, 27 Dec 2016 17:34:02 -0800

On 12/27/16, Laslo Hunhold <dev_AT_frign.de> wrote:
> I am unsure how to deal with this patch. I personally have an
> NTD-daemon running and it does all my time-manipulations. I can imagine
> that maybe manually setting your time is a good thing for debugging,
> testing, joking, whatever, but is it really worth the added complexity?
>
> What do the others think?

I think we should apply the patch because
- It is behavior specified by POSIX.
- It allows you to set your system clock without running an NTP
daemon, or without internet access.
- The patch is pretty straightforward and not too complex.

One suggestion I can think of, since the date format is simple and
uses fixed sizes, it to just parse into struct tm manually rather than
restructuring the date string into a new buffer with spaces.

For example (untested):
static int date_field(char *s, size_t i) {
  return (s[i] - '0') * 10 + (s[i+1] - '0');
}

char *s = argv[0];
tm->tm_mon = date_field(s, 0) - 1;
tm->tm_day = date_field(s, 2);
tm->tm_hour = date_field(s, 4);
tm->tm_min = date_field(s, 6);
switch (len) {
case 8:
  tm->tm_year = now->tm_year;
  break;
case 10:
  tm->tm_year = date_field(s, 8);
  if (tm->tm_year < 69)
    tm->tm_year += tm->year < 69 ? 2000 : 1900;
  break;
case 12:
  tm->tm_year = date_field(s, 8) * 100 + date_field(s, 10);
  break;
}
Received on Wed Dec 28 2016 - 02:34:02 CET

This archive was generated by hypermail 2.3.0 : Wed Dec 28 2016 - 02:36:16 CET