Date Functions
|
05-08-2014, 12:49 PM
(This post was last modified: 05-08-2014 12:50 PM by Thomas_Sch.)
Post: #1
|
|||
|
|||
Date Functions
for missing date functions have a look at
http://forum.hp-prime.de/discussion/100/...ime#Item_7 "Datumsfunktionen für HP Prime" by Wolfgang, (in german) |
|||
09-19-2014, 05:55 PM
(This post was last modified: 09-19-2014 07:53 PM by Wolfgang.)
Post: #2
|
|||
|
|||
RE: Date Functions
Here the Date functions.
Wolfgang I'm very sorry: you'll need this too: DF.TXT 1st please compile DF, 2nd compile DTFX Wolfgang HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more |
|||
01-14-2015, 10:17 PM
Post: #3
|
|||
|
|||
RE: Date Functions
Here is a newer 'all in one' programm hull
Code:
HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more |
|||
01-15-2015, 08:16 AM
Post: #4
|
|||
|
|||
RE: Date Functions
why is there a forbidden range in the dates?
|
|||
01-15-2015, 08:35 AM
Post: #5
|
|||
|
|||
RE: Date Functions
presumably because of the calendar refinement in 1582 by Pope Gregory XIII.
(http://en.wikipedia.org/wiki/Gregorian_calendar ; http://en.wikipedia.org/wiki/Adoption_of...n_calendar ) |
|||
01-15-2015, 08:38 AM
Post: #6
|
|||
|
|||
RE: Date Functions
Thank you for this info.
|
|||
01-15-2015, 01:21 PM
(This post was last modified: 01-15-2015 01:22 PM by Dieter.)
Post: #7
|
|||
|
|||
RE: Date Functions
(01-15-2015 08:16 AM)ww63 Wrote: why is there a forbidden range in the dates? Simple – because these dates did not exist. The switch from the former Julian to the current Gregorian calendar occured after Thursday, 4 Oct 1582 (last Julian date) which was immediately followed by Friday, 15 Oct 1582 (first Gregorian date). So the 10 days in between do not exist by definition. On the other hand, some countries all over the world adopted the new calendar earlier, some later, some not before the 20th century. For instance, Great Britain and its colonies did not change before 1752, so in these parts of the world the old Julian calendar still existed and there actually was a, say, 5 Oct 1582. Dieter |
|||
01-15-2015, 03:35 PM
Post: #8
|
|||
|
|||
RE: Date Functions
@Thomas and Dieter:
Thank you two for explaining, I didn't enter this section of our forums yesterday! There is a lot of a Calendar Systems: http://en.wikipedia.org/wiki/Calendar or http://de.wikipedia.org/wiki/Liste_der_Kalendersysteme HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more |
|||
01-15-2015, 07:49 PM
(This post was last modified: 01-16-2015 06:45 AM by Dieter.)
Post: #9
|
|||
|
|||
RE: Date Functions
(01-15-2015 03:35 PM)Wolfgang Wrote: @Thomas and Dieter: You're welcome. May I suggest a bit of streamlining of your program collection that would vastly reduce its size? You could write a unified Julian day number routine that would handle all possible cases so that the same formula (the one with 365.25 and 30.6001) would not have to appear numerous times in slighty different versions. In the end all possible calculations boil down to conversions between day/month/year and Julian day numbers. Additional routines could split input (nd values) into day, month and year. What do you think? Checking for invalid dates during the switchover period in October 1582 can be handled in various ways. The most straightforward way could be coded in PASCAL like this: Code: if (frac(nd)=0.101582) and (int(nd) >= 5) and (int(nd) <= 14) then The DT2DN (Date to Day Number) routine uses a special way of determining the day of year for a given date. Why don't you simply evaluate the difference between this date and 1 January (plus 1) ?-) Finally, since the program uses English dialogues, English names for the Easter-related holidays would make sense. Maybe users from various parts of the world can say which Easter-related holidays are important to them, e.g. Pentecost, Ascension Thursday etc. Dieter |
|||
01-15-2015, 10:37 PM
Post: #10
|
|||
|
|||
RE: Date Functions
Hi Dieter,
thank you very much for having a look to my code and your good suggestions! You are right, its quick and dirty..... O.T.: 30 Years ago i coded COBOL and ASSEMBLER and C on Mainframes. And i saw, that smart coding after compiling often ran with lower speed.... and NO, i wasn't paid for each column...... The DT2DN routine is independent from the other routines. The purposes of 'my' routines are: Orbit, position, distance, sunrise, sunset, twilight, and so on... of the sun. (Thats the reason for AN2J and AJ2N).. For the equation of time (coming soon) there are many ways leading to rome, too. .... I'm sorry about my bad english, in german i could it explain much better. There is no problem to make an american version of Date of Easter including the appropriate names. Next time i'll take a critical look to the code (next weeks). Everybody is invited to help me in a constructively way like this! Thank you! HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more |
|||
01-16-2015, 08:40 AM
(This post was last modified: 01-16-2015 04:57 PM by Dieter.)
Post: #11
|
|||
|
|||
RE: Date Functions
(01-15-2015 10:37 PM)Wolfgang Wrote: 30 Years ago i coded COBOL and ASSEMBLER and C on Mainframes. At that time I tried my first programs in PL/I. ;-) But I soon switched to Pascal – never looked back. Quote:And i saw, that smart coding after compiling often ran with lower speed.... I think we can have both elegant, readable and fast code. Quote:Next time i'll take a critical look to the code (next weeks). Here is a first suggestion for the N2J routine. It handles dates between 1 Jan 4713 BC and 31 Dec 9999. Input between 5 and 14 Oct 1582 (undefined) is rejected. Caution! I never wrote a single line of code for the Prime calculator, so the following code most probably will cause syntax errors and will not run without more or less significant modifications. I assume the Prime uses something similar to Pascal, so I tried it this way. ;-) Code: EXPORT N2J(nd) This is not much more than half the original size, and I think it's far more readable. Maybe you can give it a try. Dieter |
|||
01-18-2015, 06:25 PM
(This post was last modified: 01-18-2015 08:40 PM by Dieter.)
Post: #12
|
|||
|
|||
RE: Date Functions
(01-16-2015 08:40 AM)Dieter Wrote: Here is a first suggestion for the N2J routine. It handles dates between 1 Jan 4713 BC and 31 Dec 9999. Input between 5 and 14 Oct 1582 (undefined) is rejected. Finally for the record: Here is the VBA function I use in Excel (where the built-in functions have a very limited working range and may even return wrong results): Code:
In VBA, the backslash "\" stands for integer division, like IDIV or INT÷ on some HP calculators or DIV in some programming languages. Undefined dates (during the Julian/Gregorian transition) or dates before 4713 B.C. return negative results. An additional line of code could call an error handler. Please note that the Julian/Gregorian transition point can be individually adjusted by the constants in the initial two lines. LastJulian is the Julian day number of the last date of the Julian calendar (here: 4 Oct 1582 = JD 2299160), while FirstGregorian represents the first date according to the Gregorian calendar (here: +11 days = 15 Oct 1582). So if you want to reflect the situation in Great Britain and its colonies where they switched from Wed, 2 Sep to Thu, 14 Sep 1752, simply set LastJulian=2361221 and FirstGregorian=LastJulian+12. Dieter |
|||
01-19-2015, 04:47 PM
Post: #13
|
|||
|
|||
RE: Date Functions
Quote:At that time I tried my first programs in PL/I. ;-) But I soon switched to Pascal – never looked back. You don't have to look back if you are using COBOL; it is imperative, procedural and, since 2002, object-oriented. COBOL is primarily used in business, finance, and administrative systems for companies and governments.... You can i.e. use both COBOL and ORACLE, to handle a lot of data records in business environments. PASCAL is for teaching students and solving technical or scientific utilization. I think, today you can choose the most suitable programming language from a great pool. Quote:YMD:=10000*Y+100*M+D; // build YYYYMMDDVery good idea!! Such as handling transition points, i will try code it. Thank u very much, dieter. Becaue of your prename, do you speak german? (PM). HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more |
|||
01-19-2015, 08:25 PM
(This post was last modified: 01-19-2015 09:20 PM by Dieter.)
Post: #14
|
|||
|
|||
RE: Date Functions
(01-19-2015 04:47 PM)Wolfgang Wrote: You don't have to look back if you are using COBOL; it is imperative, procedural and, since 2002, object-oriented. My last and only COBOL experience dates back to 1985. ;-) (01-19-2015 04:47 PM)Wolfgang Wrote: COBOL is primarily used in business, finance, and administrative systems for companies and governments.... I love PASCAL for its sheer elegance. I'm not a profossional programmer, I just love writing compact and elegant algorithms for mathematical applications. On the other hand I also like the challenges of more assembler-like languagues as they are used in classic HP RPN calculators. ;-) (01-19-2015 04:47 PM)Wolfgang Wrote:Quote:YMD:=10000*Y+100*M+D; // build YYYYMMDDVery good idea!! There is a more elegant way that shines up in the last VBA example I posted. If the Julian day number is calculated anyway, you can also use it for comparing dates. The suggested version with a configurable transition point (via LastJulian and FirstGregorian) can be handled even simpler – like this: Code: Const LastJulian = 2299160 ' last Julian date = 04 Oct 1582 This version needs just one constant (LastJulian = Julian day number of the last date of the Julian calendar, here 2299160 = 4 Oct 1582). If the calculated JDN (according to the Julian calendar) is greater than this limit (i.e. the date belongs to the Gregorian period), it gets the Gregorian adjustment. If the new Gregorian JDN now is ≤ LastJulian, the entered date was within the transition period (here 5...14 Oct 1582) and thus is undefined. (01-19-2015 04:47 PM)Wolfgang Wrote: Thank u very much, dieter. Becaue of your prename, do you speak german? (PM). You bet / aber klar doch. :-) There is a substantial number of German speaking contributors here. But of course this is an international forum, so they all resort to today's lingua franca. ;-) Dieter |
|||
04-09-2015, 03:03 PM
Post: #15
|
|||
|
|||
RE: Date Functions
(01-15-2015 10:37 PM)Wolfgang Wrote: The DT2DN routine is independent from the other routines. hi Wolfgang, I'm using the "all in one" program in post #3 and it's very impressive! Thank you for sharing. I'm searching also just for sunrise, sunset, twilight, effemeridi of sun and moon (other planets also?)... Then, you should think to give an option to calc DDAYS with an option: to calculate with and without the "holidays days" included (like the banks sometimes require)... Danke, ciao Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
04-10-2015, 06:38 PM
Post: #16
|
|||
|
|||
RE: Date Functions
Hi Salvo,
i'm very sorry about my late responding! Thank you very much for using my date functions 'lib'! I'm searching also just for sunrise, sunset, twilight, effemeridi of sun and moon (other planets also?)... ------> For Sun the algorithms are completed and i have only to code it. DDAYS ---> holidays: Do you mean a single block like ferragosto in the middle of august? Wolfgang HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more |
|||
04-10-2015, 07:27 PM
Post: #17
|
|||
|
|||
RE: Date Functions
(04-10-2015 06:38 PM)Wolfgang Wrote: For Sun the algorithms are completed and i have only to code it. hi, I mean this and also to calculate the time without sundays and saturdays: time between minus Sun, Sat, Holidays (the most important, but I know that they are Country-related, like "Ferragosto" in Italy or Independence Day and so on...). For Sun ok! Also Moon Phases could make the Prime a companion of "little astronomer" ciao Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
04-13-2015, 10:03 PM
Post: #18
|
|||
|
|||
RE: Date Functions
Hi Salvo,
please give me hyperlinks to real examples of excluding weekends or holidays for calculating credits. I did not find those kinds of charging interests in the WWW. Moon (and planets and all others like DFX3): My programs are programmed during rare free time sections [for HP Prime] and are for free and so there is for me - look @ Surefire - no hastle guarantee! - for further upgrades. BUT: You are all invited to improve my codes! But if you can wait til this year: My personal roadmap will proceed this & more this year. I like responds via PM. Greetings Wolfgang HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more |
|||
04-13-2015, 10:17 PM
Post: #19
|
|||
|
|||
RE: Date Functions
(04-13-2015 10:03 PM)Wolfgang Wrote: Hi Salvo,hi Wolfgang, for now I found some ideas here or here... (I "googled" "days interval holidays")... Quote:Moon (and planets and all others like DFX3):I can wait, sure I can also try to test your code, hoping to improve it, if needed, but sure it's already good enough Have a nice day! Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
04-13-2015, 10:50 PM
Post: #20
|
|||
|
|||
RE: Date Functions
Hi Salvo,
thank you very much for hyperlinking! But (i have no anticipation): This is real for charging interests? Very interesting! :-) Tanti saluti da Berlino Wolfgang HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)