0

I am working with a time series data set which is in Julian days since the origin (1-1-1). I am using function chron from chron package to do the conversion from Julian days to gregorian date. However, in order to check my result, besides testing my results in R I also decided to compare it with a couple of websites (for exemple, http://www.timeanddate.com/date/durationresult.html) that counts the number of days in between two dates. Below is a reproducible code:

library('chron')
date <- seq(from=729391,to=729756,by=30)
d.year <- 1
d.month <- 1
d.day <- 1
new.date <- chron(date,origin. = c(d.year,d.month,d.day), out.format = 'year-d-m')

When I run the following code I should get 0 for all elements, if the conversion was done correctly.In fact I do get 0:

> library('lubridate')
> ymd(as.character(new.date)) - ymd('0001-01-01') - date
Time differences in days
 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0

When a compare it with the websites I get different results from. For example for the element new.date[1] (which is 1998-Jan-03) I use the website cited above to count the number of day in between 0001-01-01 and 1998-Jan-03 and I get 729,393 while I should get 729,391. I know the website is including the start date in the computation, even though there is still a difference of 1. Thank you if you could shed any light on this.

Alan Alves
  • 61
  • 1
  • 2
  • 9

1 Answers1

2

The Gnu EMACS calendar tool gives 729,392 inclusive, which is equivalent to a difference of 792,391; it uses the Gregorian calendar when computing days in an interval. It also states that January 1, AD 1, Gregorian is the same actual day as January 3, AD 1, Julian. So if some other website treated dates before 1582 as Julian dates, it would be counting from January 1, AD 1 Julian (which is December 30, 1 BC Gregorian) to January 3, 1998, Gregorian, and would result in a count that is two days greater than if both ends of the interval were regarded as Gregorian.

By the way the original Gnu EMACS calendar was done by Edward Reingold; he and Nachum Dershowitz wrote Calendrical Calculations, published by Cambridge University Press.

Gerard Ashton
  • 560
  • 4
  • 16
  • Kind of like the Excel(Windows) version of the start of the last century? – IRTFM Jun 27 '15 at 00:36
  • The Excel (Windows) problem supposedly was an effort to be compatible with Lotus 123, which was just wrong. The choice of some web sites to use Julian up to and including 4 October 1582 and using Gregorian beginning 15 October 1582 is a deliberate choice; that is what was really done in places that adopted the Gregorian calendar on the date the Pope asked them to. – Gerard Ashton Jun 27 '15 at 03:26