| View previous topic :: View next topic |
| Author |
Message |
paziu n00b

Joined: 24 Nov 2006 Posts: 62 Location: N.Carolina
|
Posted: Wed Jun 27, 2012 1:08 pm Post subject: [solved] coreutils - date ( misleading documentation? ) |
|
|
Hello Everybody,
I am trying to find out more about the syntax of the date command - I looked in the man pages from 2002, 2010, and several I found on the net.
The problem I got might seem to look trivial to some, but it cost me some explanations, and of course admitting to the mistake.
For years I have been under impression, that only "date -s" changes the time, this is what I learned in the 90s on SCO.
For one or another reason I issued "date nnnnnnnnn" command using a string format that I wanted to test if it will "spit out" the correct date, before I decide to set it. Unfortunately it changed the year to 2030 - 10 seconds after the fact I re-set it to the correct date, but than I found out that "-s" is not needed since the system changed the time, and it caused a "bit" of a problem on the production database system.
There is no trace on any man page, that says that the time can be changed without providing any switches, options, etc.
Of course, "mea culpa" but on the other hand it seems like 'date', like on the AT&T version, should be required to provide the "-s" to imply the date change, otherwise either error out, or >>>display<<< the date reflecting the date string without changing the time....
Well, I might be completely wrong, in any case I would like to hear some opinions from you... not opinions about making such mistake, but about the "destructive" feature of date without "-s" option, and what caused that Linux 'date' ( coreutils ) is so different from some Unix systems.
Thank you everybody, have a good day,
Mike
Last edited by paziu on Wed Jun 27, 2012 2:39 pm; edited 1 time in total |
|
| Back to top |
|
 |
eccerr0r Advocate

Joined: 01 Jul 2004 Posts: 2994 Location: USA
|
Posted: Wed Jun 27, 2012 1:34 pm Post subject: |
|
|
Oh...this is trying to recall back neurons from more than 20 years...
From what I remember, my old TRS-Xenix box did not use -s ... It had to be a valid date, else it would not set the date. I guess this is similar to what I've been using with Linux for a while.
I so rarely use 'date' anymore to set time, mostly do it in BIOS if I can/have to reboot the machine. If I have network access, I usually use rdate or ntp to set the date, which is a lot more accurate than carefully watching the seconds... _________________ Core-i7-2700K@4.1GHz/8GB RAM/180GB SSD/Intel HD3000 graphics
What the heck am I advocating? |
|
| Back to top |
|
 |
paziu n00b

Joined: 24 Nov 2006 Posts: 62 Location: N.Carolina
|
Posted: Wed Jun 27, 2012 1:47 pm Post subject: |
|
|
Thanks for your reply, although it does not present much value to me,
I understand, 20 years ago is in the "past", but lack or improper documentation for something as basic as "date" is "present".
I am not asking what way of setting time is better, there is situations where NTP is not available, or you have 1000 users on the system, so going in the bios to set the time during the day would cost you your job.
Thanks again,
Mike |
|
| Back to top |
|
 |
khayyam Veteran


Joined: 07 Jun 2012 Posts: 1250
|
Posted: Wed Jun 27, 2012 1:58 pm Post subject: Re: coreutils - date ( misleading documentation? ) |
|
|
| paziu wrote: | | [...] There is no trace on any man page, that says that the time can be changed without providing any switches, options, etc. Of course, "mea culpa" but on the other hand it seems like 'date', like on the AT&T version, should be required to provide the "-s" to imply the date change, otherwise either error out, or >>>display<<< the date reflecting the date string without changing the time.... |
paziu ... I can't test this right now as I'm rsync'ing some 800GB of data and don't really want the timestamps changed mid stream. Anyhow, date (gnu/coreutils) provides a '-d' switch for 'display' and I've always used this when testing a string, not because I was aware that it'd somehow be set, I had always though, as you had, that -s was required, but out of habit.
The issue may be like so: the date is of course "now" .. so if you ask "what time is it in the future" then this is somewhat meaningless and so the assumption is that you wish to set that time to "now", unless you simply ask it to '--display='. Again, I've always used '--display' and so have never had this happen, and generally thought that '--set' was required, but if I think about it the current behavior seems quite correct as why would you ask what a future time might be.
best ... khay |
|
| Back to top |
|
 |
John R. Graham Administrator


Joined: 08 Mar 2005 Posts: 6423 Location: Somewhere over Atlanta, Georgia
|
Posted: Wed Jun 27, 2012 2:16 pm Post subject: |
|
|
| date man page wrote: | | The full documentation for date is maintained as a Texinfo manual. |
| date Texinfo manual wrote: | | If given an argument that does not start with `+', `date' sets the system clock to the date and time specified by that argument... | I wish the man page were more complete as well, but it says you need to look at the Texinfo manual. The Gnu folks don't like man pages.
You can't learn to use many of the core utilities just by looking at the man pages. Other prominent examples that have much more behavior elucidated in the Texinfo manual are find and tar.
- John _________________ This space intentionally left blank. |
|
| Back to top |
|
 |
paziu n00b

Joined: 24 Nov 2006 Posts: 62 Location: N.Carolina
|
Posted: Wed Jun 27, 2012 2:20 pm Post subject: |
|
|
Thank you khayyam,
The display option would be the one I would rather expect to be the default behavior, instead of set.
In my case, I wanted to validate a date string, which did not include the year at the end - but '30' for the seconds... so the year changed to 2030.
Using "-d" is a very good idea, thank you.
I will still "stick" to my opinion, that the man page should include the default behavior if no option is provided... I am quite sure I am not the first and not the last who did this mistake....
Thank you khayyam - "-d" is now in my blood stream.
Mike |
|
| Back to top |
|
 |
paziu n00b

Joined: 24 Nov 2006 Posts: 62 Location: N.Carolina
|
Posted: Wed Jun 27, 2012 2:33 pm Post subject: |
|
|
Thank you John,
| Quote: | | If given an argument that does not start with `+', `date' sets the system clock to the date and time specified by that argument... |
texinfo describes it well, as it usually does - starting today, I will not say RFM - but RFT.
Thank you for all your replies - often "stop" and think will save from "unexpected" results.
Good Day!
Mike |
|
| Back to top |
|
 |
khayyam Veteran


Joined: 07 Jun 2012 Posts: 1250
|
Posted: Wed Jun 27, 2012 4:04 pm Post subject: |
|
|
| paziu wrote: | | The display option would be the one I would rather expect to be the default behavior, instead of set. |
paizu ... your welcome ... but it is the default behavior ... if you ask it what time is it "now":
| Code: | % date +%F
2012-06-27 |
Asking "what time/date is it in the past/future" doesn't really make any sense and so it assumes your not asking it to validate/display but to set that time to "now". If you want to know what a string will produce then you provide a --display, because it is outside of current reference.
| Code: | % date -d yesterday +%F
2012-06-26 |
| paziu wrote: | | I will still "stick" to my opinion, that the man page should include the default behavior if no option is provided... I am quite sure I am not the first and not the last who did this mistake.... |
I think its actually quite logical, its default is to provide the current reference ("now").
If you walked up to someone and said "what time will it be in five hours and 22 minutes" it has two possible meanings, 1). you don't really understand the concept of time becuase "five hours and 22 minutes" are only meaningfull with reference to a current time (ie: its 5 hours and 22 minutes before my flight to Chicago), or 2). you want to know when a certain time is "now" (ie: you trying to make sure you don't miss something that will occur at that time). Generally you would ask "what time is it" and then calculate how long you have 'til the flight leaves, or what-have-you. This is because a future time is only meaningful in reference to a current time, or an event that is to occur at that future time. So, when 'date' is provided with a string for something outside or its current reference, it assumes your using time in the same manner as outlined above, because why would you be asking "what time/date will it be in the past/future?".
I'd agree that this makes --set somewhat of an odd inclusion, but then its consistent with --display and --set ... but I'd hazard to guess that dates' behaviour is simply due to how we use time.
| paziu wrote: | | Thank you khayyam - "-d" is now in my blood stream. |
hehe ... again, your welcome ... hopefully its nothing serious :)
best ... khay |
|
| Back to top |
|
 |
eccerr0r Advocate

Joined: 01 Jul 2004 Posts: 2994 Location: USA
|
Posted: Wed Jun 27, 2012 8:11 pm Post subject: |
|
|
and don't run with scissors as root unless you want to cut something...
(also all these lineages of Un*x, some were different... BSD releases, SysV, POSIX,...) I mean, come on, why does ps have different options on different flavors?
| Code: | NAME
date - print or set the system date and time
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
Display the current time in the given FORMAT, or set the system date.
|
looks like water to me though. _________________ Core-i7-2700K@4.1GHz/8GB RAM/180GB SSD/Intel HD3000 graphics
What the heck am I advocating? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|