Dates...
-
@Lindon huh? This would mean that theres a leap year every 400 years so please tell everyone who has their birthday on the 29th of February that they won‘t live to see another birthday party…
-
@Christoph-Hart - er you should go read up on what makes a leap year, here's the code (which I couldnt be bothered writing and testing last time out - naturally lazy...):
inline function isLeapYear(year) { if(year % 400 == 0 ) { return true; }else{ if(year % 100 == 0) { return false; }else{ return year % 4 == 0; } } }
So 2000 is a leap year - but 1900 isnt.
-
@Lindon here's a little script online:
https://www.programiz.com/javascript/examples/check-leap-yearinline function isLeapYear(year) { if ((0 == year % 4) && (0 != year % 100) || (0 == year % 400)) { return true; } else { return false; } }
-
@Dan-Korneff Why not?
inline function isLeapYear(year) { return (0 == year % 4) && (0 != year % 100) || (0 == year % 400)); }
-
@d-healey That works too, and you save 4 lines of code.
-
-
@Dan-Korneff said in Dates...:
@d-healey That works too, and you save 4 lines of code.
if we are interested in saving lines of code my original version is precisely 1 line.... :-)
-
@Lindon I only skimmed the last few posts
-
if we are interested in saving lines of code my original version is precisely 1 line....
But you need to ship an update in 2036 and we're all in here for the long run...
-
@Christoph-Hart said in Dates...:
if we are interested in saving lines of code my original version is precisely 1 line....
But you need to ship an update in 2036 and we're all in here for the long run...
well you have me there...
-
@Dan-Korneff Why not?
inline function isLeapYear(year) { return (0 == year % 4) && (0 != year % 100) || (0 == year % 400)); }
except when you try this it always returns true....so it doenst work.
-- oh hang on I spot a typeo in my implementation....
-
Okay so whilst we await @ustk 's push here's a fix using just HISE:
function isLeapYear(aYear) { return ((0 == aYear % 4) && (0 != aYear % 100) || (0 == aYear % 400)); } function daysFrom2000(aYear,aMonth,aDay) { reg calcYear = 2000; reg totalDays = 0; reg leap = 0; reg monthAmounts = [31,28,31,30,31,30,31,31,30,31,30,31]; if(aYear < calcYear) return -1; if(aMonth > 2 && isLeapYear(aYear)) leap = 1; totalDays = aDay + leap; for(i = 0; i< aMonth-1; i++) { totalDays = totalDays + monthAmounts[i]; }; while(calcYear < aYear) { totalDays = totalDays + 365 + isLeapYear(calcYear); calcYear++; }; return totalDays; } Console.print(daysFrom2000(2023,01,01));
Obviously just doing days not microseconds
-
@Lindon the push’s been made, Christoph should merge soon
-
@ustk Already has, no?
Commits · christophhart/HISE
The open source framework for sample based instruments - Commits · christophhart/HISE
GitHub (github.com)
-
@d-healey Oh yes my mistake, was waiting for the others...