Why does Ruby standard library Date Module start at -4712 year? - ruby

Date.new results in # -4712-01-01.
Just as per the title, what logic am i missing, why start from -4712?

https://en.wikipedia.org/wiki/Julian_day
The Julian Period is a chronological interval of 7980 years beginning 4713 BC. It has been used by historians since its introduction in 1583 to convert between different calendars. 2015 is year 6728 of the current Julian Period. The next Julian Period begins in the year 3268 AD.

The internal representation of a Date or DateTime object is an astronomical Julian date: a fractional number of days since a "time zero" in 4712 BCE.
More information are also available in the Ruby documentation for Date.
The Julian day number is in elapsed days since noon (Greenwich mean time) on January 1, 4713 BCE (in the Julian calendar).
In this document, the astronomical Julian day number is same as the original Julian day number. And the chronological Julian day number is a variation of the Julian day number. Its days begin at midnight on local time.
From Wikipedia
The Julian day number can be calculated using the following formulas (integer division is used exclusively, that is, the remainder of all divisions are dropped):
The months (M) January to December are 1 to 12. For the year (Y) astronomical year numbering is used, thus 1 BC is 0, 2 BC is −1, and 4713 BC is −4712. D is the day of the month. JDN is the Julian Day Number, which pertains to the noon occurring in the corresponding calendar date.

Related

Time Zone format

When I find a time zone format like
"CET-1CEST,M3.5.0,M10.5.0/3"
what's the meaning of the three field? I understand the CET-1CEST but what about the last two M3.5.0 and M10.5.0/3?
I found this format in this tutorial for ESP32 NTP Time and in this list.
Well, if you scroll a little down, you'll notice that such string is called a timezone String (at least in the article). After a quick search, I came across this link, where the meaning of such string is found:
std offset dst [offset],start[/time],end[/time]
For example,
Here are some example TZ values, including the appropriate Daylight Saving Time and its dates of applicability. In North American Eastern Standard Time (EST) and Eastern Daylight Time (EDT), the normal offset from UTC is 5 hours; since this is west of the prime meridian, the sign is positive. Summer time begins on March’s second Sunday at 2:00am, and ends on November’s first Sunday at 2:00am.
EST+5EDT,M3.2.0/2,M11.1.0/2
So for CET-1CEST,M3.5.0,M10.5.0/3:
The standard timezone is CET (Central European Time)
The offset from UTC is −1
The DST timezone is CEST (Central European Summer Time)
DST starts at:
3: the third month of the year (March)
5: the last…
0: …Sunday of the month
(no time specifier, defaults to 2 AM)
DST ends at:
10: the tenth month of the year (October)
5: the last…
0: …Sunday of the month
3: at 3 AM

How to calculate month and any additional days between two dates using google sheet formula?

I want to calculate month between two date and output how month and any additional days by using google sheet
I use this formula to calculate month but i don't know how to calculate any additional days after a complete month.
DATEDIF(AG2,TODAY(),"M")
Quoting this reference of DATEDIF (emphasis mine): https://sheetshelp.com/datedif/
Syntax
=DATEDIF(start_date,end_date,unit)
start_date Date at which to start the calculation
end_date Date at which to end the calculation
unit Type of output. Choices are “Y”, “M”, “D”, “YM”, “YD”, or “MD”.
...
"M" – Number of whole months elapsed between start and end dates
"MD" – Number of days elapsed after the number of months shown with the “M” or “YM” unit. Can’t go higher than 30.
...

How can I check if a datetime is this week?

How can I check whether an email was sent this week or not from the datetime parsed from the email? For today we can do:
yourdatetime.date() < datetime.today().date()
But for a week, first we need to define what a week is, which in our case is all emails since the previous Friday. I should be able to compute it by hand, but trying to see if there are datetime functions I can use to make the code more readable for the next person.
The best you could get directly would be the use of strftime to get the week number. Extract from the page on strftime() and strptime() Behavior :
%U : Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0. Output : 00, 01, ..., 53
%W : Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0. Output : 00, 01, ..., 53
But ... this only accept either monday or sunday as first day of the week, neither friday, nor saturday. If it is not enough, you will have to develop your own algorythm in a dedicated function.

What is the extra data when I inspect a Date object?

What is the extra data included in a date object? Given the following example:
time = Time.at(1392328830)
# => 2014-02-13 15:00:30 -0700
date = time.to_date
# => #<Date: 2014-02-13 ((2456702j,0s,0n),+0s,2299161j)>
What does all this represent? It's not clear from looking at the Ruby Date documentation.
((2456702j,0s,0n),+0s,2299161j)
What you're seeing is the output from Object.inspect which is a human-readable representation of an object. In the case of the Date class:
From date.rb:
# Return internal object state as a programmer-readable string.
def inspect() format('#<%s: %s,%s,%s>', self.class, #ajd, #of, #sg) end
# Return the date as a human-readable string.
#
# The format used is YYYY-MM-DD.
def to_s() strftime end
The instance variables are:
#ajd is an Astronomical Julian Day Number
#of is an offset or fraction of a day from UTC
#sg is the Day of Calendar Reform
But what do these terms mean?
1. What is an Astronomical Julian Day Number? (#ajd)
For scientific purposes, it is convenient to refer to a date simply as a day count, counting from an arbitrary initial day. The date first chosen for this was January 1, 4713 BCE. A count of days from this date is the Julian *Day* Number or Julian *Date*. This is in local time, and counts from midnight on the initial day. The stricter usage is in UTC, and counts from midday on the initial day. This is referred to in the Date class as the Astronomical *Julian* Day *Number*. In the Date class, the Astronomical Julian Day Number includes fractional days.
2. Offset from what? (#offset)
Time zones are represented as an offset from UTC, as a fraction of a day. This offset is the how much local time is later (or earlier) than UTC. UTC offset 0 is centered on England (also known as GMT). As you travel east, the offset increases until you reach the dateline in the middle of the Pacific Ocean; as you travel west, the offset decreases.
3. What is the Day of Calendar Reform? (#sg)
The Gregorian Calendar was introduced at different times in different regions. The day on which it was introduced for a particular region is the Day *of* Calendar *Reform* for that region. This is abbreviated as sg (for Start of Gregorian calendar) in the Date class.
From what I can tell, the Gregorian Calendar is calendar that self-corrects via leap years.

Writing a weekly recurring time interval (ISO 8601)

i need a correct weekly ISO 8601 recurring time interval.
For example, repeat:
Each Monday, 19:00.
I already tried a lot of examples, but nothing worked correctly :-(
Thx for any help!
R/2014-W01-1T19:00:00/P1W
Represents a unbounded recurrence with a start date and a duration of one week. The recurrence starts at the first day (Monday) of the week number 01 in the week year 2014. I have used a week date, but you can substitute it with a calendar date or ordinal date, just make sure the date falls on a Monday.

Resources