FAB INDUSTRIES  

New media, new rules

TFTD Improvements

I have just released an improved version of my Thought for the Day app for PICO-8:

TFTD Cart 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:

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
– 30 –

Back to home