Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the origin of numeric dates starting with 6?

Tags:

date

r

I have dates as numeric, all starting with digit 6, I know that x date is between startDate and endDate.

Example data:

#dput(df1)
df1 <- structure(list(
  startDate = structure(c(9748, 11474, 12204, 12204), class = "Date"),
  endDate = structure(c(16645, 16535, 13376, 15863), class = "Date"),
  x = c(63719L, 63622L, 60448L, 62940L)), 
  row.names = c(NA, -4L), class = "data.frame")

?as.Date suggests many origins, none works:

as.Date(63719, origin = "1900-01-01")
# [1] "2074-06-16"
as.Date(63719, origin = "1899-12-30")
# [1] "2074-06-14"
as.Date(63719, origin = "1904-01-01")
# [1] "2078-06-15"
as.Date(63719, origin = "1970-01-01")
# [1] "2144-06-16"

Any ideas?

like image 346
zx8754 Avatar asked Apr 05 '19 08:04

zx8754


People also ask

What does numeric date mean?

A date- number is a numeric value representing the number of days since the date origin, usually Jan 1, 1904. The fractional part, if any, represents the time-of-day as a fraction of a 24-hour day.

What is the number part of a date called?

In most calendar systems, the date consists of three parts: the (numbered) day of the month, the month, and the (numbered) year. There may also be additional parts, such as the day of the week.


Video Answer


2 Answers

The origin could be MUMPS origin date "1840-12-31", the reason for this date is explained in MUMPS Language faq:

27. "What happened in 1841?"

When I decided on specifications for the date routine, I remembered reading of the oldest (one of the oldest?) U.S. citizen, a Civil War veteran, who was 121 years old at the time. Since I wanted to be able to represent dates in a Julian-type form so that age could be easily calculated and to be able to represent any birth date in the numeric range selected, I decided that a starting date in the early 1840s would be 'safe.' Since my algorithm worked most logically when every fourth year was a leap year, the first year was taken as 1841. The zero point was then December 30, 1840...

That's the origin of December 31, 1840 or January 1, 1841. I wasn't party to the MDC negotiations, but I did explain the logic of my choice to members of the Committee.

Wikipedia System time:

Language/Application    Function or variable    Resolution  Epoch or range
MUMPS                   $H (short for $HOROLOG) 1 s         31 December 1840

Let's test:

df1$xClean <- as.Date(df1$x, origin = "1840-12-31")
df1$xClean > df1$startDate & df1$xClean < df1$endDate
# [1] TRUE TRUE TRUE TRUE

Note: Thanks to @Frank for pointing me to this blogpost which led me to original MUMPS faq. I posted self-answer Q&A for reference, as searching SO and Google didn't yield much.

like image 56
zx8754 Avatar answered Nov 08 '22 07:11

zx8754


You found already an answer, but for the fun of it, here a code snippet to automatize this:

library(rvest)
library(tidyverse)
library(magrittr)

df1 <- structure(list(
  startDate = structure(c(9748, 11474, 12204, 12204), class = "Date"),
  endDate = structure(c(16645, 16535, 13376, 15863), class = "Date"),
  x = c(63719L, 63622L, 60448L, 62940L)), 
  row.names = c(NA, -4L), class = "data.frame")

epochs <- read_html("https://en.wikipedia.org/wiki/Epoch_(computing)") %>%
  html_nodes(xpath = '//*[@id="mw-content-text"]/div/table') %>%
  html_table() %>%
  extract2(1) %>%
  set_names(c("epoch", "users", "rationale")) %>%
  mutate(epoch_date = parse_date(epoch, "%B %d, %Y", locale = locale("en"))) %>%
  filter(!is.na(epoch_date)) 

potential_origins <- map_lgl(epochs$epoch_date,
                             function(origin) {
                               d <- as.Date(df1$x, origin = origin)
                               all(d >= df1$startDate & d <= df1$endDate)
                             })

epochs$users[potential_origins]
# [1] "MUMPS programming language"
like image 38
thothal Avatar answered Nov 08 '22 08:11

thothal