I have just released an improved version of my Thought for the Day app for PICO-8:
The app is listed on the PICO-8 BBS and therefore available within PICO-8 itself with the SPLORE
command. The source code is also hosted on GitHub.
This new version now uses a much more precise algorithm to calculate the Imperial date fraction which should also account for leap years:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
function imp_date(y,m,d,h)
--is this a leap year?
if y%4==0 and y%100!=0 then
leap=true
elseif y%400==0 then
leap=true
else
leap=false
end
--days to date
if leap==false then
ld=0
else
ld=1
end
if m==1 then
d2d=d
elseif m==2 then
d2d=d+31
elseif m==3 then
d2d=d+ld+59
elseif m==4 then
d2d=d+ld+90
elseif m==5 then
d2d=d+ld+120
elseif m==6 then
d2d=d+ld+151
elseif m==7 then
d2d=d+ld+181
elseif m==8 then
d2d=d+ld+212
elseif m==9 then
d2d=d+ld+243
elseif m==10 then
d2d=d+ld+273
elseif m==11 then
d2d=d+ld+304
elseif m==12 then
d2d=d+ld+334
end
--hours to date
local h2d=(d2d*24-24)+h
--hours in a year
if leap==true then
hiy=8784
else
hiy=8760
end
--elapsed hours in thousandth
--of a year
local id=h2d/(hiy/1000)
return flr(id)
end
|