1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 22:40:50 +00:00

Wikibase: Do not automatically convert dates to julian

This commit is contained in:
gnosygnu 2016-11-10 12:27:46 -05:00
parent d2d58f2b7e
commit 9c95e2d470
4 changed files with 19 additions and 19 deletions

View File

@ -71,7 +71,6 @@ public class Wbase_claim_time extends Wbase_claim_base {
public void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs, byte[] ttl) {
try {
Wbase_date date = this.Time_as_date();
if (this.Calendar_is_julian()) date = Wbase_date_.To_julian(date);
Wbase_date_.To_bfr(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
} catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, this.Pid(), Err_.Message_gplx_log(e));
@ -80,7 +79,6 @@ public class Wbase_claim_time extends Wbase_claim_base {
public static void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs
, byte[] ttl, byte[] pid, Wbase_date date, boolean calendar_is_julian) {
try {
if (calendar_is_julian) date = Wbase_date_.To_julian(date);
Wbase_date_.To_bfr(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
} catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, pid, Err_.Message_gplx_log(e));

View File

@ -36,22 +36,23 @@ public class Wbase_date_ {
return new Wbase_date(year * year_sign, month, day, hour, minute, second, precision, before, after, calendar_is_julian);
}
public static Wbase_date To_julian(Wbase_date date) {
int a = (int)Math_.Floor((14 - date.Month() / 12));
int y = (int)date.Year() + 4800 - a;
int m = date.Month() + 12 * a - 3;
int julian = date.Day() + (int)Math_.Floor((153 * m + 2) / 5) + 365 * y + (int)Math_.Floor(y / 4) - (int)Math_.Floor(y / 100) + (int)Math_.Floor(y / 400) - 32045;
int c = julian + 32082;
int d = (int)Math_.Floor((4 * c + 3) / 1461);
int e = c - (int)Math_.Floor((1461 * d) / 4);
int n = (int)Math_.Floor((5 * e + 2) / 153);
int new_y = d - 4800 + (int)Math_.Floor(n / 10);
int new_m = n + 3 - 12 * (int)Math_.Floor(n / 10);
int new_d = e - (int)Math_.Floor((153 * n + 2) / 5) + 1;
long a = (long)Math_.Floor((14 - date.Month() / 12));
long y = date.Year() + 4800 - a;
long m = date.Month() + 12 * a - 3;
long julian = date.Day() + (long)Math_.Floor((153 * m + 2) / 5) + 365 * y + (long)Math_.Floor(y / 4) - (long)Math_.Floor(y / 100) + (long)Math_.Floor(y / 400) - 32045;
long c = julian + 32082;
long d = (long)Math_.Floor((4 * c + 3) / 1461);
long e = c - (long)Math_.Floor((1461 * d) / 4);
long n = (long)Math_.Floor((5 * e + 2) / 153);
long new_y = d - 4800 + (long)Math_.Floor(n / 10);
int new_m = (int)(n + 3 - 12 * (long)Math_.Floor(n / 10));
int new_d = (int)(e - (long)Math_.Floor((153 * n + 2) / 5) + 1);
return new Wbase_date(new_y, new_m, new_d, date.Hour(), date.Minute(), date.Second(), date.Precision(), date.Before(), date.After(), date.Calendar_is_julian());
}
public static void To_bfr(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
boolean calendar_is_julian = date.Calendar_is_julian();
if (calendar_is_julian) date = To_julian(date);
// TOMBSTONE: use "actual" date; do not do conversion to julian; DATE:2016-11-10
// boolean calendar_is_julian = date.Calendar_is_julian();
// if (calendar_is_julian) date = To_julian(date);
long year = date.Year();
int months_bgn = msgs.Month_bgn_idx();
byte[][] months = msgs.Ary();
@ -110,8 +111,9 @@ public class Wbase_date_ {
}
break;
}
if (calendar_is_julian)
bfr.Add(msgs.Time_julian());
// TOMBSTONE: use "actual" date; do not do conversion to julian; DATE:2016-11-10
// if (calendar_is_julian)
// bfr.Add(msgs.Time_julian());
Xto_str_beforeafter(bfr, tmp_fmtr, tmp_bfr, msgs, date);
}
private static void Xto_str_beforeafter(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {

View File

@ -45,7 +45,7 @@ public class Wbase_date_tst {
fxt.Test_xto_str("+00000123456-01-01T00:00:00Z", 4, "in 100,000 years");
}
@Test public void Xto_str_julian() {
fxt.Init_calendar_is_julian_(Bool_.Y).Test_xto_str("+00000001600-01-02T00:00:00Z", Wbase_date.Fmt_ymd, "18 Jan 1600<sup>jul</sup>");
fxt.Init_calendar_is_julian_(Bool_.Y).Test_xto_str("+00000001600-01-02T00:00:00Z", Wbase_date.Fmt_ymd, "2 Jan 1600");
}
@Test public void Xto_str_before_after() {
String date = "+00000002001-02-03T04:05:06Z";

View File

@ -38,7 +38,7 @@ public class Wdata_visitor__html_wtr_tst {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Bry_.Empty, Bry_.new_a7("http://www.wikidata.org/entity/Q1985786"))
, "4:05:06 25 Feb 2001<sup>jul</sup>" // NOTE: "Feb 3" is "Feb 25" in julian time
, "4:05:06 3 Feb 2001"
);
}
@Test public void Quantity_ubound_lbound() {