Post Reply 
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
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: A tiny New Year's programming challenge - Dieter - 01-23-2015 08:25 PM



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