-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BC/BCE dates #28
Comments
It shows whatever date.getFullYear returns, modulo 10,000; see formatFullYear. Regarding the leading zeroes, as the README says,
You can drop the zero padding by using d3.timeFormat("%-m/%-d/%-Y")(new Date(117, 1, 2)) // "2/2/117"
d3.timeFormat("%-m/%-d/%-Y")(new Date(-17, 1, 2)) // "2/2/-17" (Also note the confusing behavior of the JavaScript Date constructor in regards to the full year argument…) The reason for this behavior is primarily for symmetry with parsing: the parser needs to know how many characters to consume for the I agree that the documentation isn’t particularly explicit about this behavior, and that the behavior tends to assume a roughly modern era, at least in the year range 1000-9999. It seems like you are asking for two things:
|
Are JavaScript Date objects able to faithfully represent B.C./BCE or pre-1000 years? |
@curran Valid dates range from -100,000,000 days to +100,000,000 days relative to January 1, 1970 UTC. That’s approximately ±273,785 years, so yes. Edit: although, it depends on what you mean by “faithfully” since JavaScript extrapolates the modern Gregorian calendar to previous eras, and there was greater diversity in calendar systems in the past. |
@mbostock Very interesting! Thank you for clarifying. |
@mbostock Thanks for the clarification on how the parsing works on the javascript end of things. Yes, so basically, I would like those two things: the absolute integer value of the year, and an era directive (%E, or whatever you think is appropriate). Locales would probably be necessary in the long term. I don't want to get into a philosophical debate, but it might be easiest to use BCE, CE as a default when there is no locale set. E.g., the French locale era would be "av. J.-C." for BC and "apr. J.-C." for AD. |
Hmm. Are you sure the absolute value of the full year is correct? I thought that 1 CE follows 1 BCE, and that there is no 0 CE (or 0 BCE). If you just had the absolute value of the full year, you would get 0 CE when date.getFullYear() returns 0, and 1 BCE when date.getFullYear() returns -1. I believe it would be more accurate to get 1 - date.getFullYear() whenever date.getFullYear() returns a value less than 1, so that you get 1 BCE and 2 BCE respectively for these cases. |
It's true that 1 CE follows 1 BCE. As far as I can tell, there's no real standard in Javascript for 1 BC. Is it 0 like ISO 8601 dictates or is it -1 according to XSD? Here's an old discussion from four years ago: http://scholarslab.org/research-and-development/parsing-bc-dates-with-javascript/ I tried the following:
And it printed "Thu Jun 24 -0001 00:00:00 GMT-0400 (LMT)" for me (and d.getFullYear() is -1). This makes me think that -1 is "-0001" according to the way that XSD dates operate. Whether this is conscious or not, I am not sure. If I replace -1 with 0, then it outputs the year 1900. So 0 is basically invalid. So I do think we want to return the absolute value of .getFullYear. |
As a side note: The situation with XSD is not that clear as there are two versions which handle years differently: in version 1.0 a year value of zero was invalid (as described above), in version 1.1 a year zero is valid, and the interpretation of year values changed to: year value zero => 1 BC, year value -1 => 2 BC etc. see: https://www.w3.org/TR/xmlschema11-2/#changes
I'm not sure if these Gregorian/Julian Calendar dates are the best dating system/values to store in any database when dealing with (ancient) historical dates... thinking of using Julian Day Numbers for storing & doing calculations and converting these on the fly into (proleptic) Julian for displaying on web pages. |
Hmm, this is highly problematic for software implementations, as our triplestore, Apache Fuseki, will error on "0000"^^xsd:date, and Java/Saxon date-based math functions in XSLT ignore "0000", e.g., it would say that the day after "-0001-12-31" is "0001-01-01" |
yeah, to quote Hugh in sosol/sosol#114: "I think we may actually be in Hell" |
For whatever it's worth, I verified that the largest positive and negative dates representable are "-271820-01-01T00:00:00.000Z" and "+275760-09-12T24:00:00.000Z". So if you've got restaurant reservations in the year 275,761, you're out of luck. |
Localized formatting of dates in standard JavaScript has improved significantly since this library was first created. For example: const date = new Date(-50, 0, 1);
date.toLocaleString(undefined, {year: "numeric", era: "short"}); // "51 BC"
date.toLocaleString(undefined, {year: "numeric", era: "long"}); // "51 Before Christ" More examples in this notebook: |
There is currently no way to format the era when attempting to render B.C./BCE or pre-1000 years.
For the sake of expediency, an era flag should only yield "BCE" or "CE", since these both come after the year, but A.D. is supposed to proceed it.
First, does d3 conform to ISO 8601 or the XSD variant for BCE dates? That is to say, ISO 8601 dictates that "0000" is 1 BCE, "-0010" is 11 BCE. XSD is more compatible with direct integer representations, so "-0001" is 1 BCE, and "0000" is an invalid xsd:gYear.
With that said, I have attempted to format "0010" (10 CE) as "%Y", and the output is still "0010". Furthermore, there is no flag for era ("%E" would be nice), so "-0010" cannot be designated as BCE).
Ideally, "%Y" should convert a 4-character ISO date into an integer, so that a source xsd:gYear of "-0050" can be formatted with "%Y %E" into "50 BCE"
The text was updated successfully, but these errors were encountered: