[DM15] Date manipulation

Contributed software for the DM10, DM11, DM12, DM15 and DM16 goes here.

Please prefix the subject of your post with the model of the calculator that your program is for.
Post Reply
grsbanks
Posts: 1122
Joined: Tue Apr 25, 2017 11:23 am
Location: Preston, Lancs, UK
Contact:

[DM15] Date manipulation

Post by grsbanks »

Here are a few functions for the HP-15C/DM15 that allow you to manipulate dates.

Dates are represented in "dd.mmyyyy" format if flag 0 is clear, or "mm.ddyyyy" format if flag 0 is set.

Before using any of the below functions, run "[GSB] .0" to initialise a few constants used throughout.

[A] converts a date in dd.mmyyyy (or mm.ddyyyy if F? 0) format into its Julian date number

[ B ] does the opposite of [A] by taking a Julian date number and converting it to dd.mmyyyy (or mm.ddyyyy) format

[C] takes a date in dd.mmyyyy (or mm.ddyyyy) format and gives you the day of the week from 0 (Sunday) to 6 (Saturday)

[D] takes a number of days (e.g. the difference between two Julian date numbers) and expresses it in weeks and days as ww.d

[E] does the opposite of [D] by taking a number of weeks and days ww.d and expressing it in days

Note that registers R0 to R6 are used in these functions and Flag 0 determines whether dates are interpreted/returned in dd.mmyyyy (clear) or mm.ddyyyy (set) format.

The Julian date number of a date is an integer that identifies the date in time. The progression is linear, so a date that is 'n' days in the future or the past from now has a Julian date number that is greater or smaller than today's Julian date number by 'n'.

To calculate the Julian date number of the date d/m/y (or m/d/y for our American cousins):

If m is 1 or 2:
Let Y' = y - 1 and let M' = m + 13

If m is 3 or greater:
Let M' = m + 1 and let Y' = y

Julian date number J = int(Y' x 365.25) + int(M' x 30.6001) + d + 1720982

To perform the reverse operation and get the "normal" date from a Julian date number:

Let J' = J - 1720982

Y' = int( (J' - 122.1) / 365.25 )

M' = int( (J' - int(Y' x 365.25)) / 30.6001 )

d = J' - int(M' x 30.6001) - int(Y' x 365.25)

if M' is 13 or lower:
m = M' - 1 and y = Y'

if M' is 14 or 15:
m = M' - 13 and y = Y' + 1

The day of the week is:

DOW = (J' + 5) MODULO 7

Examples:

I'm European so I'll be using dd/mm/yyyy format throughout. If you'd rather use mm/dd/yyyy then just make sure you set flag 0.

Run [GSB] .0 before using any of these programs:

Code: Select all

[GSB] .0 => 1,720,982.000
What is today's Julian date number (store the result in R7 so we can use it again):

Code: Select all

29.062019 [GSB] [A] => 2,458,664.000
[STO] 7
How many days is it until Christmas this year?

Code: Select all

25.122019 [GSB] [A] => 2,458,843.000
[RCL] [-] 7 => 179.0000
Christmas is 179 days off. What's that in weeks and days?

Code: Select all

[GSB] [D] => 25.4000
That's 25 weeks and 4 days away.

What day of the week was Christmas last year?

Code: Select all

25.122018 [GSB] [C] => 2.0000
It was a Tuesday. How long ago was that?

Code: Select all

25.122018 [GSB] [A] [RCL] 7 [x<>y] [-] => 186.0000
[GSB] [D] => 26.4000
It was 186 days ago, or 26 weeks and 4 days.

I just replaced the battery in a calculator that I hardly ever use. It has a capacity of 220mAh and the calculator sucks 6μA out of it when switched off. Assuming the battery just keeps on going until it's flat and then cuts out and assuming I never actually use the calculator again, on what date will the battery die?

Step 1 - find out how many days the battery is good for:

Code: Select all

220 [EEX] [CHS] 3 [ENTER] 6 [EEX] [CHS] 6 [÷] => 36,666.6667
24 [÷] [g] [INT] => 1,527.0000
The battery is good for 1527 days. What date does that bring us to?

Code: Select all

[RCL] 7 [+] => 2,460,191.000
[STO] 8 (we'll want this for later)
[GSB] [B] [f] [PREFIX] => 3092023000
So, I should replace the battery before the 3rd of September 2023.

Just to be on the safe side I'll do that, say, 12 weeks before. What date is 12 weeks before 3/9/2023?

Code: Select all

12 [GSB] [E] [RCL] 8 [x<>y] [-]
[GSB] [B] [f] [PREFIX] => 1106202300
Answer: 11th June 2023.

Dump:

Code: Select all

DM15_M1B
04  000000fffff000  00000000000008  0000000000000c  0000000001eeae
08  00000000000000  2faf8befbe2280  00000000000000  00000000000000
14  00000000000000  1b2d2d2d2d2d2d  000000000006e3  00000000000000
18  00000000000000  0000000000007f  00000000a00000  00000000000000
e0  00000000000000  00000000000000  00000000000000  00b283cffdf0f1
e4  fbfcf73353efeb  fdf7430eb2fafc  f0f1a3c5fcf7eb  c10db2ebfaf5c0
e8  fcf7a3fdf7faf5  240cb283cfc483  dffdf2c6c550ff  353443fdf6c636
ec  0375ef0213a296  efa5dfc512ed35  f3f144fbc533fa  ebc0cf36ebc1cf
f0  45ebe1cfc3a3cf  ebc0cf46ebe0cf  fbf1c0f2f2f143  05a2cf0bb283cf
f4  3483dfebc1cf35  43ebc0cf360185  dff3f176ef0011  a295ef10ed35f2
f8  46fcf4c6a3c496  c49350ff97f5eb  c1fcf2c6a3c445  44ebc104b282cf
fc  240ab242f2f8f9  f0f2f7f141f1f0  f0f6c0f0f340f5  f2c0f5f6f300ff
A: 000000fffff000  B: 000000fffff000  C: 0000000001eeae
S: 00000000000000
M: 000000fffff000  N: 00000000000000  G: 04
Listing:

Code: Select all

LBL .0
365.25
STO 0
30.6001
STO 1
1720982
STO 2
RTN
LBL A
GSB 4
RCL+ 2
RTN
LBL 4
ENTER
INT
STO 4
STO 5
R↓
FRAC
EEX
2
×
ENTER
INT
5
STO I
F? 0
DSE I
R↓
STO (i)
R↓
FRAC
EEX
4
×
STO 6
2
RCL 5
x≤y
GTO 0
ISG 5
CLx
GTO 1
LBL 0
DSE 6
13
STO+ 5
LBL 1
RCL 6
RCL× 0
INT
STO 3
RCL 5
RCL× 1
INT
STO+ 3
RCL 4
RCL+ 3
RTN
LBL B
RCL- 2
LBL 5
STO 3
122.1
-
RCL÷ 0
INT
STO 6
RCL× 0
INT
RCL- 3
CHS
RCL÷ 1
INT
STO 5
RCL× 1
INT
RCL 6
RCL× 0
INT
+
RCL 3
x<>y
-
STO 4
13
RCL 5
x≤y
GTO 2
x<>y
STO- 5
ISG 6
CLx
GTO 3
LBL 2
DSE 5
LBL 3
RCL 6
EEX
6
÷
STO 3
RCL 4
RCL 5
F? 0
x<>y
EEX
2
÷
STO+ 3
R↓
RCL+ 3
RTN
LBL C
GSB 4
5
+
7
÷
FRAC
7
×
.5
+
INT
RTN
LBL E
ENTER
INT
7
×
x<>y
FRAC
10
×
+
RTN
LBL D
STO 3
7
÷
INT
x<> 3
RCL 3
7
×
-
10
÷
RCL+ 3
RTN
There are only 10 kinds of people in the world: those who understand binary and those who do not.
Post Reply