1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-05-31 22:44:34 +00:00

Wikibase: Return timezone as integer, not string

This commit is contained in:
gnosygnu 2016-10-28 09:24:28 -04:00
parent e10aace5f9
commit 4e3df30cc0
3 changed files with 59 additions and 2 deletions

View File

@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
public class Keyval_find_ {
public static Keyval Find(boolean fail, Keyval[] root, String... keys) {
Keyval found = null;
Keyval[] kvs = root;
int keys_len = keys.length;
for (int i = 0; i < keys_len; ++i) {
String key = keys[i];
int kvs_len = kvs.length;
found = null;
for (int j = 0; j < kvs_len; ++j) {
Keyval kv = kvs[j];
if (String_.Eq(kv.Key(), key)) {
found = kv;
break;
}
}
if (found == null) {
if (fail)
throw Err_.new_wo_type("could not find key", "key", key);
else
break;
}
if (i == keys_len - 1)
return found;
else
kvs = (Keyval[])found.Val();
}
return found;
}
}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import org.junit.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*;
public class Scrib_lib_wikibase_srl_tst {
@Before public void init() {fxt.Clear();} private Scrib_lib_wikibase_srl_fxt fxt = new Scrib_lib_wikibase_srl_fxt();
@ -360,6 +360,14 @@ public class Scrib_lib_wikibase_srl_tst {
, ""
);
}
@Test public void Claims_time_typed() {
Wbase_claim_time claim = (Wbase_claim_time)fxt.Wdata_fxt().Make_claim_time(2, "2001-02-03 04:05:06", 9);
Scrib_lib_wikibase_srl_visitor visitor = new Scrib_lib_wikibase_srl_visitor();
visitor.Visit_time(claim);
Keyval keyval = Keyval_find_.Find(true, visitor.Rv(), "value", "timezone");
Gftest.Eq__str("timezone", keyval.Key());
Gftest.Eq__int(0, (int)keyval.Val()); // fails when keyval.Val() is String; DATE:2016-10-28
}
}
class Scrib_lib_wikibase_srl_fxt {
private Wdata_doc_bldr wdoc_bldr;

View File

@ -71,7 +71,7 @@ class Scrib_lib_wikibase_srl_visitor implements Wbase_claim_visitor {
rv[1] = Keyval_.new_(Wbase_claim_time_.Itm__precision.Key_str() , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
rv[2] = Keyval_.new_(Wbase_claim_time_.Itm__before.Key_str() , itm.Before_int());
rv[3] = Keyval_.new_(Wbase_claim_time_.Itm__after.Key_str() , itm.After_int());
rv[4] = Keyval_.new_(Wbase_claim_time_.Itm__timezone.Key_str() , Wbase_claim_time_.Dflt__timezone.Val_str()); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
rv[4] = Keyval_.new_(Wbase_claim_time_.Itm__timezone.Key_str() , Wbase_claim_time_.Dflt__timezone.Val_int()); // ASSUME: always 0 b/c UTC?; DATE:2015-09-21
rv[5] = Keyval_.new_(Wbase_claim_time_.Itm__calendarmodel.Key_str() , Wbase_claim_time_.Dflt__calendarmodel.Val_str());
return rv;
}