calendrical | Fourmilab Calendar Converter as a library | Calendar library
kandi X-RAY | calendrical Summary
kandi X-RAY | calendrical Summary
[Fourmilab Calendar Converter] as a library.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of calendrical
calendrical Key Features
calendrical Examples and Code Snippets
Community Discussions
Trending Discussions on calendrical
QUESTION
I currently use the following code to return an array of dates for every single day between two dates, including today's date and the last date itself. This works great.
- However, how would I go about modifying what I'm already doing in order to do the same exact thing otherwise, but instead return an array of the date of every Friday between the dates? For example, if the function was called on Wed Oct 23rd 2019 to return every Friday until November 10th, the first date would be Fri the 25th, Nov 1st, and then Nov 8th.
- How would I do the same thing as above but for the 1st of every month? If I called the function on Wed Oct 23rd 2019 to return the first of every month until December 16th. The array should have Nov 1st and Dec 1st in it.
ANSWER
Answered 2019-Oct-24 at 05:19You just need to add a weekday parameter to your method and check if the weekday of the date inside the loop before adding it to your array:
QUESTION
Algorithms for the following:
JD 1099114.5
PHP: 3 Mar -1704 12:00:00 (PHP Internal convertor)
...ANSWER
Answered 2017-Aug-15 at 11:26I did not look at the Fliegel-Van Flandern algorithm. I tested the remaining algorithm for the test cases Danny F requested, and added the last noon the Julian calendar was observed in Rome (JD 2299160) and the first noon of the Gregorian calendar in Rome (JD 2299161). For non-integer Julian days, I only used the Meeus algorithm since that's the only one that says it supports non-integers.
The internal algorithm was correct, when you allow for considering year 0 to not exist, and it always converts to Gregorian. The Meeus algorithm is correct, when you allow for it assuming the existence of year 0, and converting to Julian for October 4, 1582 and earlier, and to Gregorian for dates after that.
The Richards algorithm required corrections. Rather than using the floor function at certain points, I used the intdiv function in place of every "/" operator, which more closely follows Richard's description of the algorithm. After these corrections, the test cases were successful. (Richards considers the year 0 to exist and always converts to Gregorian.)
QUESTION
I did some more research the following is the output for the respective algorithms:
JD 1099114.5
PHP: 3 Mar 1704 B.C.E. 12:00:00 (PHP Internal convertor) FLN: 0 Mar 1703 B.C.E. 12:00:00 (Fliegel-Van Flandern) MEU: 18 Mar 1703 B.C.E 12:00:00 (Jean Meeus "Astronomical Algorithms, 2nd ed., corrected) RICH: 4 Mar 1703 B.C.E. 12:00:00 (Richards in Explanatory Supplement 3rd Ed.)
Each Algorithm has its issues and quirks about starting times etc.
Meeus assumes that there is a Gregorian year 0 (between -1 and 1), even if this is astronomically correct, it makes little sense from a calendrical perspective. Technically then all the results to convert into Gregorian dates is just wrong?
...ANSWER
Answered 2017-Aug-08 at 12:46Meeus' Algorithm is actually in error (thank you Paul for pointing this out) there should be no 0 in Gregorian years, which means that all dates prior to Gregorian year 1 (i.e. Gyr < 0) are in error. Post Gyr (Gyr >= 1) are correctly converted. Also, he only has the convertor for dates post 1582G.
It seems therefore that the correct date is that listed by the jdtogregorian converter supplied by PHP.
QUESTION
I frequently see people who assume that DATEDIFF(YEAR, date_of_birth, GETDATE())
will produce the current age of the person.
Unfortunately this is not correct. The DATEDIFF
function, at least in SQL Server, does not count the number of full years between two dates - it counts the number of calendrical boundaries crossed.
That is, in the case of the YEAR
parameter, DATEDIFF
counts the number of 1-Januaries crossed. With the MONTH
parameter, it would count the number of 1sts of the month crossed.
So for example, a baby born on 31-Dec-17 would already be "1 years old", when in fact they do not turn 1 years old until 31-Dec-18, and they are currently 0 years old.
The use of the DATEDIFF
function in this way is equivalent to writing YEAR(GETDATE()) - YEAR(date_of_birth)
, which of course takes no account of where the person's birthday falls inside the year.
Having reviewed a good sample of other questions here, there does not appear to be a definitive answer, and there are many answers that are quite wrong.
So my question is, what is the simplest expression that, given a person's date of birth and a reference date, calculates the age of a person as of that reference date?
I'm looking for an answer in the following terms:
The answer should be an inline expression - capable of being selected or incorporated into a where-clause.
The answer should be robust and have no erroneous corner cases - however infrequent or implausible those cases are. It should work for newborn babies and for persons that would be centuries old, should cope with leap years, and ideally should be capable of representing the period prior to birth as a minus number (with the person becoming -1 years old on the day before they were born).
The answer should be numerically precise - it should not rely on using an average number of days per year or dividing by magic numbers, and rounding off the error. I believe all trivial approaches which use rounding, have corner cases and are therefore not robust, but I stand to be corrected.
For those with birthdays falling on the 29-Feb, it should treat their age as incrementing on 29-Feb if the reference year is a leap year, or it should treat their age as incrementing on 1-Mar if the reference year is not a leap year.
The answer should disregard any time component of either the birthdate or the reference date - that is, the person should be assumed to have been born at midnight, and their age should increment at midnight on subsequent birthdays.
I'm interested in an answer for SQL Server particularly, but would also be interested to see answers for any other database platform.
EDIT: I appreciate the answers that have been given and the links to previous questions. This question has now been marked as a duplicate.
What strikes me is that the accepted answer to the link given, is cluttered and begins with an incorrect implementation, and the comments on it refer to its implementation being incorrect - it was only after I read it carefully that I saw it had been updated with a correct implementation (sandwiched between a treatment of "decimal age" which is not related to my question). The third answer, which has also attracted a substantial number of up-votes, is also incorrect. There are also a myriad of other answers of varying quality.
I've also asked for an answer that, ideally, correctly handles "negative ages" in some way (where the reference date is before the birth date), and the linked answers do not. Therefore, whilst my question treats the same subject, it is not a duplicate, as I've imposed several additional constraints that are not present in that question, and which would invalidate (in one way or another) all the answers given on that older question.
To be honest, given how many subtly wrong answers abound (as I alluded to above in my first paragraph), I would have thought this question would get more upvotes and more interest, rather than a downvote and 3 votes to close.
...ANSWER
Answered 2018-Feb-12 at 22:50Pseudo:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install calendrical
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page