A tiny New Year's programming challenge
01-23-2015, 08:25 PM (This post was last modified: 01-23-2015 08:32 PM by Dieter.)
Post: #24
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: A tiny New Year's programming challenge
(01-22-2015 01:50 PM)wynen Wrote:  I suppose, I'm a bit late for a "New Year's" programming challenge, but I want to contribute a HP-16C program to convert calender date representations.

Thank you very much for your contribution. I do not have access to a 16C, so I cannot try your program. I assume it is based on integer arithmetics. Does it also work for negative (B.C.) years?

(01-22-2015 01:50 PM)wynen Wrote:  My solution uses a subroutine to convert a (proleptic) Gregorian Calender date YYYY-MM-DD to a Julian Day Number (i.e. the Julian Date as of YYYY-MM-DDT12:00Z).
(...)
• Julian Day Number
if mm > 2 then m := mm-3; y:=yyyy else m := mm+12; y := yyyy-1 endif
JDN(yyyy-mm-dd) := 365*y + y/4 - y/100 + y/400 + (153*m+2)/5 + dd + 1721119

I think it's not mm+12 in the "else" branch, but mm+9. This is also what your program calculates: it first evaluates mm–3 and, if this is <0 (i.e. mm=1..2) it adds 12 back, giving in total mm+9.

(01-22-2015 01:50 PM)wynen Wrote:
• Ordinal number of a calendar day within the calendar year (Calender day of the year, CDY)
CDY = JDN(yyyy-mm-dd) - JDN(yyyy-01-01)

+1, I would say, or use JDN(yyyy-01-00). Otherwise 1 Jan is day 0.

(01-22-2015 01:50 PM)wynen Wrote:
• Ordinal number of a calendar week within the year (Calender week, CW)

I think I''ll have to take a closer look at that. Have you tried the examples in my initial post?

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread A tiny New Year's programming challenge - Dieter - 01-01-2015, 04:51 PM RE: A tiny New Year's programming challenge - Gerald H - 01-01-2015, 06:00 PM RE: A tiny New Year's programming challenge - Dieter - 01-02-2015, 07:17 AM RE: A tiny New Year's programming challenge - Gerald H - 01-05-2015, 08:29 PM RE: A tiny New Year's programming challenge - Gerald H - 01-02-2015, 10:29 AM RE: A tiny New Year's programming challenge - Dieter - 01-03-2015, 07:04 AM RE: A tiny New Year's programming challenge - Gilles - 01-02-2015, 10:16 PM RE: A tiny New Year's programming challenge - Dieter - 01-03-2015, 06:58 AM RE: A tiny New Year's programming challenge - Gilles - 01-03-2015, 01:24 PM RE: A tiny New Year's programming challenge - Dieter - 01-03-2015, 06:20 PM RE: A tiny New Year's programming challenge - Dieter - 01-04-2015, 06:37 PM RE: A tiny New Year's programming challenge - Werner - 01-05-2015, 10:55 AM RE: A tiny New Year's programming challenge - Dieter - 01-05-2015, 07:45 PM RE: A tiny New Year's programming challenge - Werner - 01-05-2015, 09:21 PM RE: A tiny New Year's programming challenge - Werner - 01-06-2015, 04:11 PM RE: A tiny New Year's programming challenge - Dieter - 01-07-2015, 12:21 AM RE: A tiny New Year's programming challenge - walter b - 01-07-2015, 02:55 AM RE: A tiny New Year's programming challenge - walter b - 01-07-2015, 06:24 AM RE: A tiny New Year's programming challenge - Thomas Klemm - 01-07-2015, 04:50 AM RE: A tiny New Year's programming challenge - Werner - 01-07-2015, 08:19 AM RE: A tiny New Year's programming challenge - Dieter - 01-07-2015, 01:46 PM RE: A tiny New Year's programming challenge - wynen - 01-22-2015, 01:50 PM RE: A tiny New Year's programming challenge - Dieter - 01-23-2015 08:25 PM RE: A tiny New Year's programming challenge - Damien - 01-22-2015, 11:24 PM RE: A tiny New Year's programming challenge - Dieter - 01-23-2015, 08:39 PM RE: A tiny New Year's programming challenge - Damien - 01-23-2015, 09:47 PM RE: A tiny New Year's programming challenge - Dieter - 01-23-2015, 10:07 PM

User(s) browsing this thread: 1 Guest(s)