Talk:Last Friday of each month: Difference between revisions
Walterpachl (talk | contribs) →1582: new section |
Walterpachl (talk | contribs) →1582: new section |
||
Line 85: | Line 85: | ||
:: I have a similar problem with [[OpenBSD]] 4.9. The output changes from run to run, and might show the last Mondays, Thursdays, Fridays or Saturdays. After the call to strptime(), <code>tm.tm_wday</code> contains junk values like 50237728 or 239567136. (Legal values are 0 to 6.) Change to "%d-01-01 09:01:01" and "%Y-%m-%d %H:%M:%S" is no help. Checking my manuals, [http://www.openbsd.org/cgi-bin/man.cgi?query=mktime&sektion=3&arch=amd64&apropos=0&manpath=OpenBSD+4.9 mktime(3)] describes the fields of ''struct tm'', but [http://www.openbsd.org/cgi-bin/man.cgi?query=strptime&apropos=0&sektion=0&manpath=OpenBSD+4.9&arch=amd64&format=html strptime(3)] is vague; I assume that strptime() never fills ''tm_wday'' unless the string contains the weekday. --[[User:Kernigh|Kernigh]] 01:05, 9 November 2011 (UTC) |
:: I have a similar problem with [[OpenBSD]] 4.9. The output changes from run to run, and might show the last Mondays, Thursdays, Fridays or Saturdays. After the call to strptime(), <code>tm.tm_wday</code> contains junk values like 50237728 or 239567136. (Legal values are 0 to 6.) Change to "%d-01-01 09:01:01" and "%Y-%m-%d %H:%M:%S" is no help. Checking my manuals, [http://www.openbsd.org/cgi-bin/man.cgi?query=mktime&sektion=3&arch=amd64&apropos=0&manpath=OpenBSD+4.9 mktime(3)] describes the fields of ''struct tm'', but [http://www.openbsd.org/cgi-bin/man.cgi?query=strptime&apropos=0&sektion=0&manpath=OpenBSD+4.9&arch=amd64&format=html strptime(3)] is vague; I assume that strptime() never fills ''tm_wday'' unless the string contains the weekday. --[[User:Kernigh|Kernigh]] 01:05, 9 November 2011 (UTC) |
||
== 1582 == |
|||
4 Oct 1582 is followed by 15 Oct 1582 in the Gregorian Calendar. |
|||
Java seems to take care of that. Rexx results differ: |
|||
<pre> |
|||
25.09.1582 |
|||
26.09.1582 |
|||
27.09.1582 |
|||
28.09.1582 Fri |
|||
29.09.1582 |
|||
30.09.1582 |
|||
01.10.1582 |
|||
02.10.1582 |
|||
03.10.1582 |
|||
04.10.1582 |
|||
15.10.1582 Fri |
|||
16.10.1582 |
|||
17.10.1582 |
|||
18.10.1582 |
|||
19.10.1582 |
|||
20.10.1582 |
|||
21.10.1582 |
|||
22.10.1582 Fri |
|||
23.10.1582 |
|||
24.10.1582 |
|||
25.10.1582 |
|||
26.10.1582 |
|||
27.10.1582 |
|||
28.10.1582 |
|||
29.10.1582 Fri |
|||
30.10.1582 |
|||
31.10.1582 |
|||
Java Rexx |
|||
Jän 26 Friday 29 Jan 1582 |
|||
Feb 23 Friday 26 Feb 1582 |
|||
Mär 30 Friday 26 Mar 1582 |
|||
Apr 27 Friday 30 Apr 1582 |
|||
Mai 25 Friday 28 May 1582 |
|||
Jun 29 Friday 25 Jun 1582 |
|||
Jul 27 Friday 30 Jul 1582 |
|||
Aug 31 Friday 27 Aug 1582 |
|||
Sep 28 Friday 24 Sep 1582 <--- different |
|||
Okt 29 Friday 29 Oct 1582 |
|||
Nov 26 Friday 26 Nov 1582 |
|||
Dez 31 Friday 31 Dec 1582 |
|||
</pre> |
|||
--[[User:Walterpachl|Walterpachl]] 06:05, 11 August 2012 (UTC) |
|||
== 1582 == |
== 1582 == |
Revision as of 06:05, 11 August 2012
command line
Why does the task specify that the year is supplied from the command line? This seems to conflate two totally separate language capabilities--date arithmetic and command line handling. For the PHP example, I'm just ignoring the command line requirement. --Showell 17:37, 20 January 2012 (UTC)
task name
of year? not of month?--eMBee 13:43, 7 November 2011 (UTC)
- It looks like it's all of the last fridays of the months of a given year? --Rdm 14:52, 7 November 2011 (UTC)
- yes, exactly, which is why i find the current title confusing. something like Last Friday of every month would be more to the point. otherwise, i thought the original title was sufficient. something about fridays. it is clear enough that this is about the calendar. is more details really needed?--eMBee 14:59, 7 November 2011 (UTC)
- English is not my born language, but I also find the title "Last Fridays of year" confusing. I understand it as 'really' the last fridays of a given year, for example the last three Fridays of 2012 are 2012-12-14, 2012-12-21 and 2012-12-28. Blue Prawn 21:10, 9 November 2011 (UTC)
- exactly my thoughts too. so what's a better title? "last friday of each month?" (i thin kthe fact that it is for a year is less interesting, the same solution would work for any period of time).--eMBee 04:11, 10 November 2011 (UTC)
- I'm not particularly attached to the current name; I just thought that the original (“Last Fridays”) wasn't good enough either. Suggested changes are welcome. –Donal Fellows 08:49, 10 November 2011 (UTC)
- exactly my thoughts too. so what's a better title? "last friday of each month?" (i thin kthe fact that it is for a year is less interesting, the same solution would work for any period of time).--eMBee 04:11, 10 November 2011 (UTC)
- English is not my born language, but I also find the title "Last Fridays of year" confusing. I understand it as 'really' the last fridays of a given year, for example the last three Fridays of 2012 are 2012-12-14, 2012-12-21 and 2012-12-28. Blue Prawn 21:10, 9 November 2011 (UTC)
- yes, exactly, which is why i find the current title confusing. something like Last Friday of every month would be more to the point. otherwise, i thought the original title was sufficient. something about fridays. it is clear enough that this is about the calendar. is more details really needed?--eMBee 14:59, 7 November 2011 (UTC)
C version
This discussion is about the program shown here:
<lang c>#define _XOPEN_SOURCE
- include <stdio.h>
- include <time.h>
int main(int c, char *v[]) { int days[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int m, y, w; struct tm tm; char buf[32];
if (c < 2 || !sscanf(v[1], "%d", &y)) return 1;
days[1] -= y % 4 || (y % 100 && ! (y % 400)); sprintf(buf, "%d-1-1", y); strptime(buf, "%Y-%m-%d", &tm); w = tm.tm_wday - 1; /* day of week for zeroth of Jan */
for(m = 0; m < 12; m++) { w = (w + days[m]) % 7; printf("%d-%02d-%d\n", y, m + 1, days[m] + (w < 5 ? -2 : 5) - w); }
return 0;
}</lang>
Building the C version under cygwin (gcc 3.4.4), I get:
<lang bash>$ make last_fridays cc last_fridays.c -o last_fridays
$ ./last_fridays 2011 2011-01-27 2011-02-24 2011-03-31 2011-04-28 2011-05-26 2011-06-30 2011-07-28 2011-08-25 2011-09-29 2011-10-27 2011-11-24 2011-12-29
$ ./last_fridays 2012 2012-01-27 2012-02-24 2012-03-30 2012-04-27 2012-05-25 2012-06-29 2012-07-27 2012-08-31 2012-09-28 2012-10-26 2012-11-30 2012-12-28
$ cc --version cc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</lang>
The C entry currently shows different results for 2011, but I cannot reproduce them. --Rdm 23:25, 8 November 2011 (UTC)
- I'll assume it's a cygwin bug for now. For the record, can you change two lines to
- <lang>sprintf(buf, "%d-01-01 09:01:01", y);
strptime(buf, "%Y-%m-%d %H:%M:%S", &tm);</lang> and see how it does? --unsigned
- I replaced the sprintf an strptime lines with these two lines and got the same result. Note also that might results are consistent (but this does not prove that the issue is not uninitialized memory). --Rdm 11:17, 9 November 2011 (UTC)
- I have a similar problem with OpenBSD 4.9. The output changes from run to run, and might show the last Mondays, Thursdays, Fridays or Saturdays. After the call to strptime(),
tm.tm_wday
contains junk values like 50237728 or 239567136. (Legal values are 0 to 6.) Change to "%d-01-01 09:01:01" and "%Y-%m-%d %H:%M:%S" is no help. Checking my manuals, mktime(3) describes the fields of struct tm, but strptime(3) is vague; I assume that strptime() never fills tm_wday unless the string contains the weekday. --Kernigh 01:05, 9 November 2011 (UTC)
- I have a similar problem with OpenBSD 4.9. The output changes from run to run, and might show the last Mondays, Thursdays, Fridays or Saturdays. After the call to strptime(),
1582
4 Oct 1582 is followed by 15 Oct 1582 in the Gregorian Calendar. Java seems to take care of that. Rexx results differ:
25.09.1582 26.09.1582 27.09.1582 28.09.1582 Fri 29.09.1582 30.09.1582 01.10.1582 02.10.1582 03.10.1582 04.10.1582 15.10.1582 Fri 16.10.1582 17.10.1582 18.10.1582 19.10.1582 20.10.1582 21.10.1582 22.10.1582 Fri 23.10.1582 24.10.1582 25.10.1582 26.10.1582 27.10.1582 28.10.1582 29.10.1582 Fri 30.10.1582 31.10.1582 Java Rexx Jän 26 Friday 29 Jan 1582 Feb 23 Friday 26 Feb 1582 Mär 30 Friday 26 Mar 1582 Apr 27 Friday 30 Apr 1582 Mai 25 Friday 28 May 1582 Jun 29 Friday 25 Jun 1582 Jul 27 Friday 30 Jul 1582 Aug 31 Friday 27 Aug 1582 Sep 28 Friday 24 Sep 1582 <--- different Okt 29 Friday 29 Oct 1582 Nov 26 Friday 26 Nov 1582 Dez 31 Friday 31 Dec 1582
--Walterpachl 06:05, 11 August 2012 (UTC)
1582
4 Oct 1582 is followed by 15 Oct 1582 in the Gregorian Calendar. Java seems to take care of that. Rexx results differ:
25.09.1582 26.09.1582 27.09.1582 28.09.1582 Fri 29.09.1582 30.09.1582 01.10.1582 02.10.1582 03.10.1582 04.10.1582 15.10.1582 Fri 16.10.1582 17.10.1582 18.10.1582 19.10.1582 20.10.1582 21.10.1582 22.10.1582 Fri 23.10.1582 24.10.1582 25.10.1582 26.10.1582 27.10.1582 28.10.1582 29.10.1582 Fri 30.10.1582 31.10.1582 Java Rexx Jän 26 Friday 29 Jan 1582 Feb 23 Friday 26 Feb 1582 Mär 30 Friday 26 Mar 1582 Apr 27 Friday 30 Apr 1582 Mai 25 Friday 28 May 1582 Jun 29 Friday 25 Jun 1582 Jul 27 Friday 30 Jul 1582 Aug 31 Friday 27 Aug 1582 Sep 28 Friday 24 Sep 1582 <--- different Okt 29 Friday 29 Oct 1582 Nov 26 Friday 26 Nov 1582 Dez 31 Friday 31 Dec 1582
--Walterpachl 06:05, 11 August 2012 (UTC)