Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

What day is tomorrow?

已查看 50 次
跳至第一个未读帖子

Luc

未读,
2023年1月23日 01:37:442023/1/23
收件人
Today is 23 so tomorrow is 24, no problem.

But if today was the 30th, how would I know what day tomorrow is?
The 31st or the 1st?

Easy. Just check what the month is.

But then I would need to maintain two lists:
30-day months and 31-day months.

And there is always February, of course. So I also have to check
if it's a leap year.

Or maybe I can just get today's Epoch, add 86400 seconds and get
the date corresponding to the resulting Epoch.

I can do all that by myself, but it definitely sounds like a wheel
that someone else has invented already.

Do you know of any? I would like to see what other tools there
might be in that toolbox.

I haven't found anything in Tcllib or Tclx.


--
Luc
>>

Harald Oehlmann

未读,
2023年1月23日 02:33:262023/1/23
收件人
clock format [clock add [clock seconds] 1 day] -format %d

Christian Gollwitzer

未读,
2023年1月23日 03:04:002023/1/23
收件人
Am 23.01.23 um 08:33 schrieb Harald Oehlmann:
> Am 23.01.2023 um 07:37 schrieb Luc:
>> Today is 23 so tomorrow is 24, no problem.
>>
>> But if today was the 30th, how would I know what day tomorrow is?
>> The 31st or the 1st?
>
> clock format [clock add [clock seconds] 1 day] -format %d
>
Or use the free-form clock parser:

clock format [clock scan tomorrow] -format %d

It also understands "now + 1 day" and similar things

Christian

Harald Oehlmann

未读,
2023年1月23日 03:10:072023/1/23
收件人
Wow, I did not know this! You learn each day! Thanks,
Harald

Arjen Markus

未读,
2023年1月23日 04:55:472023/1/23
收件人
You should be a bit careful with that: the free-form parser is a bit quirky, if I understand it correctly. One reason to stay with the more formal arithmetic.

Regards,

Arjen

Harald Oehlmann

未读,
2023年1月23日 05:01:032023/1/23
收件人
Yes, and it is depreciated. So, maybe remove it in 9.0 ;-).
But the solution by Christian is just beautiful !

Take care,
Harald

Ralf Fassel

未读,
2023年1月23日 05:03:152023/1/23
收件人
* Christian Gollwitzer <auri...@gmx.de>
But be aware of the subtle differences between "24 hours" and "1 day":

% clock format [clock scan "now"]
Mon Jan 23 10:53:41 CET 2023

% clock format [clock scan "now + 24 hours"]
Tue Jan 24 10:53:41 CET 2023

% clock format [clock scan "now + 1 day"]
Tue Jan 24 00:00:00 CET 2023

% clock format [clock scan tomorrow]
Tue Jan 24 00:00:00 CET 2023

% info patchlevel
8.6.13

I would have expected that "now + 1 day" produces the same result as
"now + 24 hours", since the docs state:

FREE FORM SCAN
relative time
A specification relative to the current time. The format is
number unit. Acceptable units are year, fortnight, month, week,
day, hour, minute (or min), and second (or sec). The unit can
be specified as a singular or plural, as in 3 weeks. These mod-
ifiers may also be specified: tomorrow, yesterday, today, now,
last, this, next, ago.

The actual date is calculated according to the following steps.

First, any absolute date and/or time is processed and converted. Using
that time as the base, day-of-week specifications are added. Next,
relative specifications are used.
!!! If a date or day is specified, and no absolute or relative
!!! time is given, midnight is used.
Finally, a correction is applied so that the correct hour of the
day is produced after allowing for daylight savings time
differences and the correct date is given when going from the end
of a long month to a short month.

(Emphasis by me)

HTH
R'

Robert Heller

未读,
2023年1月23日 07:44:332023/1/23
收件人
It is built-in: the clock command will tell you.

clock add timeVal ?count unit...? ?-option value?


proc nextdate {month date year} {
return [clock format [clock add [clock scan \
[format {%04d-%02d-%02d} $year $month $date] \
-format {%Y-%m-%d}] 1 day] -format {%m %d %Y}]
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

Gerald Lester

未读,
2023年1月23日 08:26:582023/1/23
收件人
Read the manual page for the clock command, pay attention to the section
on the clock add subcommend.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Christian Gollwitzer

未读,
2023年1月23日 14:19:212023/1/23
收件人
Am 23.01.23 um 11:00 schrieb Harald Oehlmann:
I know it is deprecated and I think it is a mistake to completely take
it away, since it has these nice features. If it is moved away, I think
it should go into something like
clock scan -format free "tomorrow"
or "clock guess tomorrow" or maybe into tcllib.

Christian

0 个新帖子