Skip to content

Commit

Permalink
Support AD and BC in year notations
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-kraemer committed Mar 11, 2024
1 parent 8551acc commit 4a63995
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void renderInternal(RenderContext ctx) {
switch (name) {
case "year":
if (date.length > 0) {
value = renderYear(date[0]);
value = renderYear(date[0], ctx);
}
break;

Expand All @@ -77,7 +77,12 @@ private void renderInternal(RenderContext ctx) {
}
}

private String renderYear(int year) {
private String renderYear(int year, RenderContext ctx) {
if (year < 0) {
return (-year) + ctx.getTerm("bc");
} else if (year < 1000) {
return year + ctx.getTerm("ad");
}
return String.valueOf(year);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,9 @@ private String applyCiteprocJs(String mode, String style, ItemDataProvider itemD
"condition_VariableNone",
"date_Accessed",
"date_AccessedCrash",
// "date_DateAD",
// "date_DateBC",
"date_DateAD",
"date_DateBC",
// we don't render error messages
// "date_DateNoDateNoTest",
"date_DateNoDateWithTest",
// "date_DayOrdinalDayOneOnly",
Expand Down
42 changes: 42 additions & 0 deletions citeproc-java/src/test/resources/fixtures/date-ad-bc-locale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
mode: bibliography

style:
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0">
<locale>
<terms>
<term name="ad">AADD</term>
<term name="bc">BBCC</term>
</terms>
</locale>
<bibliography>
<layout>
<names variable="author" suffix=". ">
<name initialize-with=". "/>
</names>
<text variable="title"/>
<date form="text" variable="issued" date-parts="year-month-day" prefix=" (" suffix=")"/>
</layout>
</bibliography>
</style>

items:
- id: item1
author:
- given: Given
family: Name
title: My title
issued:
date-parts:
- [-500]
- id: item2
author:
- given: Given
family: Name
title: My title
issued:
date-parts:
- [ 123 ]

result: |
G. Name. My title (500BBCC)
G. Name. My title (123AADD)
36 changes: 36 additions & 0 deletions citeproc-java/src/test/resources/fixtures/date-ad-bc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mode: bibliography

style:
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0">
<bibliography>
<layout>
<names variable="author" suffix=". ">
<name initialize-with=". "/>
</names>
<text variable="title"/>
<date form="text" variable="issued" date-parts="year-month-day" prefix=" (" suffix=")"/>
</layout>
</bibliography>
</style>

items:
- id: item1
author:
- given: Given
family: Name
title: My title
issued:
date-parts:
- [-500]
- id: item2
author:
- given: Given
family: Name
title: My title
issued:
date-parts:
- [ 123 ]

result: |
G. Name. My title (500BC)
G. Name. My title (123AD)

0 comments on commit 4a63995

Please sign in to comment.