Post Reply 
(15C) Julian Day to Day of Week [ISO; 12C Formula]
08-26-2016, 01:39 PM (This post was last modified: 08-27-2016 08:24 PM by Nick.)
Post: #1
(15C) Julian Day to Day of Week [ISO; 12C Formula]
Formula: ISO Day of Week = JD MOD 7 + 1
- Same formula as 12C [1 = Monday .. 7 = Sunday]

Input: X = JD (Julian Day)
Output: X = DOW (ISO Day of Week)

Size: 15 Bytes

Requires: (15C) MM.DDYYYY or DD.MMYYYY to Julian Day [Stack-Only] (or equivalent)

Note: The stack is not preserved.

Enjoy,
Nick

Code:
01 LBL 0
02 ENTER
03 ENTER
04 7
05 /
06 LSTx
07 X<->Y
08 FRAC
09 *
10 1
11 .
12 5
13 +
14 INT
15 RTN

Comments:

14 INT(x + .5) ' Rounding per precision loss during MOD
Find all posts by this user
Quote this message in a reply
09-18-2016, 05:39 PM (This post was last modified: 09-18-2016 05:57 PM by Dieter.)
Post: #2
RE: (15C) Julian Day to Day of Week [ISO; 12C Formula]
(08-26-2016 01:39 PM)Nick Wrote:  Formula: ISO Day of Week = JD MOD 7 + 1
(...)
Comments:

14 INT(x + .5) ' Rounding per precision loss during MOD

Yes, using FRAC for the mod function will produce roundoff errors.
But why don't you simply do it this way?

Code:
01 GSB 0
02 ENTER
03 ENTER
04 7
05 /
06 INT
07 7
08 *
09 -
10 1
11 +
12 RTN

That's shorter and does not require any rounding.
BTW, I assume the first step is not LBL 0 but GSB 0 (to call the JDN routine). ;-)

While we're at it: may I link to my HP35s calendar programs?
They convert from and to JDN, calculate the day of week and implement a ΔDAYS and DATE+ function and more.

Dieter
Find all posts by this user
Quote this message in a reply
08-24-2024, 12:26 PM
Post: #3
RE: (15C) Julian Day to Day of Week [ISO; 12C Formula]
I am not able to get the right number for today: 8.242024 should give 6, not 5!
Find all posts by this user
Quote this message in a reply
08-26-2024, 02:50 PM (This post was last modified: 08-26-2024 04:23 PM by ThirdPoliceMan.)
Post: #4
RE: (15C) Julian Day to Day of Week [ISO; 12C Formula]
A machine translation (DeepL) was used for the English version of this posting.

For this topic I have written somewhat more extensive routines for Day of Week, Day of Year; Week of Year (and Julian Day) for the HP15CE. The simplest form of a calendar.
It follows ISO 8601.

I used three different subroutines for this, which can also be used for other purposes or on their own.
These three routines are part of other programmes in the memory of the HP15CE and have been adapted here for the listing.
I am not a mathematician, physicist or programmer by profession, so these routines could certainly be made a little more efficient here and there. If there so, I would be grateful for any helpful suggestions.

Label B is the calendar routine (Day of Weak; Day of Year; Week of Year).
Note: No check has been programmed for the first and last week of a year (to save memory space),
the user must check the correctness himself (it is of course simple).
Usage: Day STO 1 Month STO 2 Year STO 3 f 'B'.

-------------------------------------------------
LBL B == Day of Week - Day of Year - Week of Year
-------------------------------------------------
Input

T |
Z | Day (R01)
Y | Month (R02)
X | Year (R03)

Output

T |
Z | Week of Year
Y | Day of Year
X | Day of Week


Label A is an MOD function which also outputs the integer remainder (I often need this for different things; for example: 768 ENTER 60 f 'A' = 12 Hours 48 Minutes):

------------
LBL A == MOD
------------
Input

T |
Z |
Y | numerator
X | denominator

Output

T | numerator
Z | denominator
Y | Integer ratio
X | Integer remainder


Label D is a routine that returns the Julian date for a given date.
Also applies to dates before 15-10-1582 (1582-10-15).
(Usage: Day STO 1 Month STO 2 Year STO 3 f 'D')

----------------------
LBL D == Date => JDate
----------------------
Input

T |
Z | Day (R01)
Y | Month (R02)
X | Year (R03)

Output

T |
Z |
Y |
X | Julian Day 12:00 (Noon)


Listing:

Code:

Listing:

||--------------------------------||
|| 001 | 42,21,11  | f LBL A      ||
|| 002 | 44 1      | STO 1        ||
|| 003 | 34        | x↔y          ||
|| 004 | 44 0      | STO 0        ||
|| 005 | 45,10, 1  | RCL ÷ 1      ||
|| 006 | 43 44     | g INT        ||
|| 007 | 36        | ENTER        ||
|| 008 | 45,20, 1  | RCL × 1      ||
|| 009 | 16        | CHS          ||
|| 010 | 45,40, 0  | RCL + 0      ||
|| 011 | 45 0      | RCL 0        ||
|| 012 | 33        | R-Down       ||
|| 013 | 43 32     | g RTN        ||
||--------------------------------||
|| 014 | 42,21,12  | f LBL B      ||
|| 015 | 44 .3     | STO .3       ||
|| 016 | 32 14     | GSB D        ||
|| 017 | 44 .8     | STO .8       ||
|| 018 | 1         | 1            ||
|| 019 | 48        | .            ||
|| 020 | 5         | 5            ||
|| 021 | 40        | +            ||
|| 022 | 7         | 7            ||
|| 023 | 32 11     | GSB A        ||
|| 024 | 43 20     | g x=0        ||
|| 025 | 7         | 7            ||
|| 026 | 44 .7     | STO .7       ||
|| 027 | 3         | 3            ||
|| 028 | 1         | 1            ||
|| 029 | 44 1      | STO 1        ||
|| 030 | 1         | 1            ||
|| 031 | 2         | 2            ||
|| 032 | 44 2      | STO 2        ||
|| 033 | 1         | 1            ||
|| 034 | 16        | CHS          ||
|| 035 | 45,40, .3 | RCL+ .3      ||
|| 036 | 44 3      | STO 3        ||
|| 037 | 32 14     | GSB D        ||
|| 038 | 44,30, .8 | STO- .8      ||
|| 039 | 45 .8     | RCL .8       ||
|| 040 | 1         | 1            ||
|| 041 | 0         | 0            ||
|| 042 | 40        | +            ||
|| 043 | 45,30, .7 | RCL- .7      ||
|| 044 | 7         | 7            ||
|| 045 | 10        | ÷            ||
|| 046 | 43 44     | g INT        ||
|| 047 | 45 .8     | RCL .8       ||
|| 048 | 45 .7     | RCL .7       ||
|| 049 | 43 32     | g RTN        ||
||--------------------------------||
|| 050 | 42,21,14  | f LBL D      ||
|| 051 | 34        | x↔y          ||
|| 052 | 1         | 1            ||
|| 053 | 0         | 0            ||
|| 054 | 0         | 0            ||
|| 055 | 10        | ÷            ||
|| 056 | 40        | +            ||
|| 057 | 34        | x↔y          ||
|| 058 | 26        | EEX          ||
|| 059 | 4         | 4            ||
|| 060 | 16        | CHS          ||
|| 061 | 20        | ×            ||
|| 062 | 40        | +            ||
|| 063 | 1         | 1            ||
|| 064 | 5         | 5            ||
|| 065 | 8         | 8            ||
|| 066 | 2         | 2            ||
|| 067 | 48        | .            ||
|| 068 | 1         | 1            ||
|| 069 | 0         | 0            ||
|| 070 | 1         | 1            ||
|| 071 | 5         | 5            ||
|| 072 | 43,30, 9  | g TEST x≥y   ||
|| 073 | 43, 4, 1  | g SF 1       ||
|| 074 | 2         | 2            ||
|| 075 | 45 2      | RCL 2        ||
|| 076 | 43 10     | g x≤y        ||
|| 077 | 22 0      | GTO 0        ||
|| 078 | 22 1      | GTO 1        ||
|| 079 | 42,21, 0  | f LBL 0      ||
|| 080 | 1         | 1            ||
|| 081 | 2         | 2            ||
|| 082 | 44,40, 2  | STO + 2      ||
|| 083 | 1         | 1            ||
|| 084 | 44,30, 3  | STO − 3      ||
|| 085 | 42,21, 1  | f LBL 1      ||
|| 086 | 43, 6, 1  | g F? 1       ||
|| 087 | 22 2      | GTO 2        ||
|| 088 | 22 3      | GTO 3        ||
|| 089 | 42,21, 2  | f LBL 2      ||
|| 090 | 43, 5, 1  | g CF 1       ||
|| 091 | 0         | 0            ||
|| 092 | 22 4      | GTO 4        ||
|| 093 | 42,21, 3  | f LBL 3      ||
|| 094 | 48        | .            ||
|| 095 | 0         | 0            ||
|| 096 | 1         | 1            ||
|| 097 | 45,20, 3  | RCL × 3      ||
|| 098 | 43 44     | g INT        ||
|| 099 | 36        | ENTER        ||
|| 100 | 36        | ENTER        ||
|| 101 | 4         | 4            ||
|| 102 | 10        | ÷            ||
|| 103 | 43 44     | g INT        ||
|| 104 | 34        | x↔y          ||
|| 105 | 30        | −            ||
|| 106 | 2         | 2            ||
|| 107 | 40        | +            ||
|| 108 | 42,21, 4  | f LBL 4      ||
|| 109 | 1         | 1            ||
|| 110 | 5         | 5            ||
|| 111 | 2         | 2            ||
|| 112 | 4         | 4            ||
|| 113 | 48        | .            ||
|| 114 | 5         | 5            ||
|| 115 | 30        | −            ||
|| 116 | 45,40, 1  | RCL + 1      ||
|| 117 | 1         | 1            ||
|| 118 | 45,40, 2  | RCL + 2      ||
|| 119 | 3         | 3            ||
|| 120 | 0         | 0            ||
|| 121 | 48        | .            ||
|| 122 | 6         | 6            ||
|| 123 | 0         | 0            ||
|| 124 | 0         | 0            ||
|| 125 | 1         | 1            ||
|| 126 | 20        | ×            ||
|| 127 | 43 44     | g INT        ||
|| 128 | 40        | +            ||
|| 129 | 4         | 4            ||
|| 130 | 7         | 7            ||
|| 131 | 1         | 1            ||
|| 132 | 6         | 6            ||
|| 133 | 45,40, 3  | RCL + 3      ||
|| 134 | 3         | 3            ||
|| 135 | 6         | 6            ||
|| 136 | 5         | 5            ||
|| 137 | 48        | .            ||
|| 138 | 2         | 2            ||
|| 139 | 5         | 5            ||
|| 140 | 20        | ×            ||
|| 141 | 43 44     | g INT        ||
|| 142 | 40        | +            ||
|| 143 | 43 32     | g RTN        ||
||--------------------------------||

Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 




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