How to use Ruby Date constants GREGORIAN, JULIAN, ENGLAND and even ITALY

'run uppercase, they are constants.

I enjoy learning Ruby Date helpers.

1.9.3p125 :057 > Date::ABBR_MONTHNAMES => [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] 1.9.3p125 :058 > Date::ABBR_DAYNAMES => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] 1.9.3p125 :059 > Date::MONTHNAMES => [nil, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] 1.9.3p125 :060 > Date::DAYNAMES => ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] 1.9.3p125 :070 > Date::MONTHNAMES[Time.new.month] => "August" 

Funny stuff! But what about the constants GREGORIAN, JULIAN, ENGLAND and ITALY (!). What are they for / how do I use them? I can output:

 1.9.3p125 :061 > Date::GREGORIAN => -Infinity 1.9.3p125 :062 > Date::JULIAN => Infinity 1.9.3p125 :063 > Date::ENGLAND => 2361222 

or

 1.9.3p125 :067 > Date.new => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2299161j)> 1.9.3p125 :068 > Date.new.new_start(Date::JULIAN) => #<Date: -4712-01-01 ((0j,0s,0n),+0s,Infj)> 1.9.3p125 :069 > Date.new.new_start(Date::ENGLAND) => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2361222j)> 

From the following it looks like Julian is a calendar that goes offline for a few days. I remember that I learned about the reset calendar for this several centuries ago, so it makes sense, however, ENGLAND and ITALY and how they will be used are still unclear.

 1.9.3p125 :076 > Date.new(1977,7,1).new_start(Date::ENGLAND) => #<Date: 1977-07-01 ((2443326j,0s,0n),+0s,2361222j)> 1.9.3p125 :077 > Date.new(1977,7,1).new_start(Date::ITALY) => #<Date: 1977-07-01 ((2443326j,0s,0n),+0s,2299161j)> 1.9.3p125 :078 > Date.new(1977,7,1).new_start(Date::JULIAN) => #<Date: 1977-06-18 ((2443326j,0s,0n),+0s,Infj)> 
0
source share
3 answers

All constants are explained in the documentation . Generally, if the explanations below mean nothing to you, you probably don't need to worry about these constants at all.

ENGLAND Julian day calendar reform day for England and its colony.

GREGORYAN. Julian Day of the Day of Calendar Reform for the Prolephic Gregorian Calendar

ITALY Julian day calendar reform day for Italy and some Catholic countries.

JULIA Julian day calendar reform day for the prolific Julian calendar

Here is more information about the various calendar systems:

0
source

You can go into ext / date / date_core.c and just get the values. They are constants, but you asked how to use them. Your question should be how to extract them. There it is used to calculate Date and DateTime objects, data data to create the desired time and date.

For example, it will be one that has elements with specific values.

 #<DateTime: 2017-01-06T12:05:55+00:00 ((2457760j,43555s,553855002n),+0s,2299161j)> 

Pay attention to all the parts? Two of them have j after the number. The calculation of these values ​​is what these constants are and are part of the class object. There are many ways to use them and many types. Good reading is Julian Day on Wikipedia. Take a look at the table for all of these different values. The story is also interesting in that they are related to what Michael directed you.

As for the values ​​that you returned for the two of them, note that they are also classes. This is curious because it relates to how far forward or backward in time your system can crunch numbers.

Infinity

0
source

In the Western world, a date is usually expressed using the year, month, and day. It would be the perfect way to express any day in history if the definition of our calendar had not changed in the past.

The calendar that we know today was introduced by Julius Cesar and is therefore known as the Julian calendar. Unfortunately, this had a tiny flaw. The Julian calendar uses the concept of a leap year every four years to compensate for the fact that the year is not exactly 365, but about 365.25 days. Yet this is not right; in fact, the year is a little shorter, and if you add a leap year every four years, this error will be summed up for hundreds of years, and sooner or later you will be disconnected for whole days. Today we have a leap year every four years, but not if the year is divided by 100, unless it is also divided by 1000. This is done for approximately 365.2425 days a year. The Reformation is called the Gregorian calendar after it was introduced by Pope Gregor XIII. And to make things even more complex, the Gregorian calendar was not introduced in every country at the same time.

When creating a Date object in Ruby, you can use one of four constants:

 Date.new(2019, 6, 29, Date::ITALY) Date.new(2019, 6, 29, Date::ENGLAND) Date.new(2019, 6, 29, Date::GREGORIAN) Date.new(2019, 6, 29, Date::JULIAN) 

If you use Date::ITALY , which is the default value, if you do not specify anything at all, then dates up to 1582-10-15 are interpreted as dates of the Julian calendar, all other dates are interpreted as Gregorian dates., 1582-10-15 - this is the date when Italy introduced the Gregorian calendar.

If you use Date::ENGLAND , then the dates until 1752-09-14 are interpreted as the dates of the Julian calendar, all other dates are interpreted as Gregorian dates. 1752-09-14 is the date when the British Empire, as well as the American colonies, introduced the Gregorian calendar.

If you use Date::GREGORIAN , the Date object will behave as if the Gregorian calendar was always in place, no matter what the date is. All dates, even dates prior to the Reformation, are interpreted as Gregorian dates.

If you use Date::JULIAN , the Date object will behave as if this date reformation never existed. All dates are interpreted according to the Julian calendar.

What is the correct behavior? Oh no. Different standards offer different solutions. If you need to process historical dates, you need to know by which calendar these dates should be interpreted. And since you may need a different conversion date for this, you can also pass your own integer value instead of this predefined constant. This number is then interpreted as the Julian day number when the transition to the Gregorian calendar occurred.

0
source

All Articles