a lib less one liner based on @Star-Dust 's excellent (fixed) code...
I hope it fits the width of this forum
B4X:
Public Sub dayOfYear (month As Int, dayOfMonth As Int,year As Int) As Int
Return dayOfMonth+Bit.ParseInt(Regex.Split(",","0,0,31,59,90,120,151,181,212,243,273,304,335")(month),10)+2*(0.5-Min((year Mod 4),0.5)+Min((year Mod 100),0.5)-Min((year Mod 400),0.5))*Floor(Min(month,2)/2)
End Sub
See "Avoid Magic Numbers" in the link provided by Ilan. I'm not knocking the code, I love it, but it does violate the spirit of that section of the linked article.
See "Avoid Magic Numbers" in the link provided by Ilan. I'm not knocking the code, I love it, but it does violate the spirit of that section of the linked article.
There is no magic number that appears without explanation.
It is simply a formula, like Zeller's congruence formula, which is used to calculate the day of the week of each date. They are not magic numbers, but mathematical formulas.
I do not give explanations just because I do not write well English and I get really complicated, not because it is a 'magic number' which is not explained. (Actually I do not express well even in my mother tongue, except for the Qbasic boasted an excellent pronunciation)
if you know the rules your code makes sense so yes it's just taking advantage of math trickery.
you can do a libless oneliner without the need of the extra date functions lib aswell but then you rely on the core date functions and I doubt it was allowed aswell
(a modded version of what Luka posted where you count days between Jan 1st and the given date of that year)