mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.8.1.1
This commit is contained in:
@@ -44,6 +44,14 @@ public class Pft_fmt_itm_ {
|
||||
, Tid_hebrew_month_name_full = 23
|
||||
, Tid_hebrew_month_name_gen = 24
|
||||
, Tid_hebrew_numeral = 25
|
||||
, Tid_iranian_year_idx = 26
|
||||
, Tid_iranian_month_idx = 27
|
||||
, Tid_iranian_day_idx = 28
|
||||
, Tid_iranian_month_name = 29
|
||||
, Tid_hijiri_year_idx = 30
|
||||
, Tid_hijiri_month_idx = 31
|
||||
, Tid_hijiri_day_idx = 32
|
||||
, Tid_hijiri_month_name = 33
|
||||
;
|
||||
|
||||
public static final Pft_fmt_itm
|
||||
@@ -91,6 +99,14 @@ public class Pft_fmt_itm_ {
|
||||
, Iso_fmt = new Pft_fmt_itm_iso_fmt()
|
||||
, Rfc_5322 = new Pft_fmt_itm_rfc_5322()
|
||||
, Timezone_offset = new Pft_fmt_itm_timezone_offset()
|
||||
, Iranian_year_idx = new Pft_fmt_itm_iranian_year_idx()
|
||||
, Iranian_month_idx = new Pft_fmt_itm_iranian_month_idx()
|
||||
, Iranian_day_idx = new Pft_fmt_itm_iranian_day_idx()
|
||||
, Iranian_month_name = new Pft_fmt_itm_iranian_month_name()
|
||||
, Hijiri_year_idx = new Pft_fmt_itm_hijiri_year_idx()
|
||||
, Hijiri_month_idx = new Pft_fmt_itm_hijiri_month_idx()
|
||||
, Hijiri_day_idx = new Pft_fmt_itm_hijiri_day_idx()
|
||||
, Hijiri_month_name = new Pft_fmt_itm_hijiri_month_name()
|
||||
;
|
||||
public static final Btrie_fast_mgr Regy = Btrie_fast_mgr.cs_()
|
||||
.Add(Byte_ascii.Ltr_Y , Pft_fmt_itm_.Year_len4) // 2012
|
||||
@@ -135,7 +151,15 @@ public class Pft_fmt_itm_ {
|
||||
.Add("xjx" , Pft_fmt_itm_.Hebrew_month_name_gen)
|
||||
.Add("xjY" , Pft_fmt_itm_.Hebrew_year_num)
|
||||
.Add("xh" , Pft_fmt_itm_.Hebrew_numeral)
|
||||
// TODO: foreign; space; "
|
||||
.Add("xij" , Pft_fmt_itm_.Iranian_day_idx)
|
||||
.Add("xiF" , Pft_fmt_itm_.Iranian_month_name)
|
||||
.Add("xin" , Pft_fmt_itm_.Iranian_month_idx)
|
||||
.Add("xiY" , Pft_fmt_itm_.Iranian_year_idx)
|
||||
.Add("xmj" , Pft_fmt_itm_.Hijiri_day_idx)
|
||||
.Add("xmF" , Pft_fmt_itm_.Hijiri_month_name)
|
||||
.Add("xmn" , Pft_fmt_itm_.Hijiri_month_idx)
|
||||
.Add("xmY" , Pft_fmt_itm_.Hijiri_year_idx)
|
||||
// TODO: space; "
|
||||
;
|
||||
public static Pft_fmt_itm[] Parse(Xop_ctx ctx, byte[] fmt) {
|
||||
Btrie_fast_mgr trie = Pft_fmt_itm_.Regy;
|
||||
|
||||
@@ -92,243 +92,57 @@ class Pft_fmt_itm_hebrew_numeral implements Pft_fmt_itm {
|
||||
bfr.Add_str(Pft_fmt_itm_hebrew_.Calc_hebrew_numeral(date.Year()));
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hebrew_ {
|
||||
public static int Calc_hebrew_year_num_start(int year) {
|
||||
int year_minus_1 = year - 1;
|
||||
int a = (12 * year_minus_1 + 17) % 19;
|
||||
int b = year_minus_1 % 4;
|
||||
double m = 32.044093161144d + 1.5542417966212d * a + b / 4.0 - 0.0031777940220923d * year_minus_1;
|
||||
if (m < 0)
|
||||
m--;
|
||||
int mar = (int)m;
|
||||
if (m < 0)
|
||||
m++;
|
||||
m -= mar;
|
||||
int c = (mar + 3 * year_minus_1 + 5 * b + 5) % 7;
|
||||
if (c == 0 && a > 11 && m >= 0.89772376543210d)
|
||||
mar++;
|
||||
else if (c == 1 && a > 6 && m >= 0.63287037037037d)
|
||||
mar += 2;
|
||||
else if (c == 2 || c == 4 || c == 6)
|
||||
mar++;
|
||||
double year_minus_3761 = year - 3761;
|
||||
mar += (int)(year_minus_3761 / 100 ) - (int)(year_minus_3761 / 400) - 24;
|
||||
return mar;
|
||||
}
|
||||
private static final int[] Hebrew_date_rslt = new int[4];
|
||||
public static int[] Calc_hebrew_date(DateAdp date) {
|
||||
synchronized (Hebrew_date_rslt) {
|
||||
Calc_hebrew_date(Hebrew_date_rslt, date.Year(), date.Month(), date.Day());
|
||||
return Hebrew_date_rslt;
|
||||
}
|
||||
}
|
||||
public static boolean Calc_hebrew_date(int[] rv, int year, int month, int day) { // REF.MW:Language.php|tsToHebrew
|
||||
// Calculate Hebrew year
|
||||
int hebrewYear = year + 3760;
|
||||
|
||||
// Month number when September = 1, August = 12
|
||||
month += 4;
|
||||
if (month > 12) {
|
||||
// Next year
|
||||
month -= 12;
|
||||
year++;
|
||||
hebrewYear++;
|
||||
}
|
||||
|
||||
// Calculate day of year from 1 September
|
||||
int dayOfYear = day;
|
||||
for (int i = 1; i < month; i++) {
|
||||
if (i == 6) {
|
||||
// February
|
||||
dayOfYear += 28;
|
||||
// Check if the year is leap
|
||||
if (year % 400 == 0 || (year % 4 == 0 && year % 100 > 0)) {
|
||||
dayOfYear++;
|
||||
}
|
||||
} else if (i == 8 || i == 10 || i == 1 || i == 3) {
|
||||
dayOfYear += 30;
|
||||
} else {
|
||||
dayOfYear += 31;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the start of the Hebrew year
|
||||
int start = Calc_hebrew_year_num_start(hebrewYear);
|
||||
|
||||
// Calculate next year's start
|
||||
int nextStart = 0;
|
||||
if (dayOfYear <= start) {
|
||||
// Day is before the start of the year - it is the previous year
|
||||
// Next year's start
|
||||
nextStart = start;
|
||||
// Previous year
|
||||
year--;
|
||||
hebrewYear--;
|
||||
// Add days since previous year's 1 September
|
||||
dayOfYear += 365;
|
||||
if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
|
||||
// Leap year
|
||||
dayOfYear++;
|
||||
}
|
||||
// Start of the new (previous) year
|
||||
start = Calc_hebrew_year_num_start(hebrewYear);
|
||||
} else {
|
||||
// Next year's start
|
||||
nextStart = Calc_hebrew_year_num_start(hebrewYear + 1);
|
||||
}
|
||||
|
||||
// Calculate Hebrew day of year
|
||||
int hebrewDayOfYear = dayOfYear - start;
|
||||
|
||||
// Difference between year's days
|
||||
int diff = nextStart - start;
|
||||
// Add 12 (or 13 for leap years) days to ignore the difference between
|
||||
// Hebrew and Gregorian year (353 at least vs. 365/6) - now the
|
||||
// difference is only about the year type
|
||||
if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
|
||||
diff += 13;
|
||||
} else {
|
||||
diff += 12;
|
||||
}
|
||||
|
||||
// Check the year pattern, and is leap year
|
||||
// 0 means an incomplete year, 1 means a regular year, 2 means a complete year
|
||||
// This is mod 30, to work on both leap years (which add 30 days of Adar I)
|
||||
// and non-leap years
|
||||
int yearPattern = diff % 30;
|
||||
// Check if leap year
|
||||
boolean isLeap = diff >= 30;
|
||||
|
||||
// Calculate day in the month from number of day in the Hebrew year
|
||||
// Don't check Adar - if the day is not in Adar, we will stop before;
|
||||
// if it is in Adar, we will use it to check if it is Adar I or Adar II
|
||||
int hebrewDay = hebrewDayOfYear;
|
||||
int hebrewMonth = 1;
|
||||
int days = 0;
|
||||
|
||||
while (hebrewMonth <= 12) {
|
||||
// Calculate days in this month
|
||||
if (isLeap && hebrewMonth == 6) {
|
||||
// Adar in a leap year
|
||||
if (isLeap) {
|
||||
// Leap year - has Adar I, with 30 days, and Adar II, with 29 days
|
||||
days = 30;
|
||||
if (hebrewDay <= days) {
|
||||
// Day in Adar I
|
||||
hebrewMonth = 13;
|
||||
} else {
|
||||
// Subtract the days of Adar I
|
||||
hebrewDay -= days;
|
||||
// Try Adar II
|
||||
days = 29;
|
||||
if (hebrewDay <= days) {
|
||||
// Day in Adar II
|
||||
hebrewMonth = 14;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (hebrewMonth == 2 && yearPattern == 2) {
|
||||
// Cheshvan in a complete year (otherwise as the rule below)
|
||||
days = 30;
|
||||
} else if (hebrewMonth == 3 && yearPattern == 0) {
|
||||
// Kislev in an incomplete year (otherwise as the rule below)
|
||||
days = 29;
|
||||
} else {
|
||||
// Odd months have 30 days, even have 29
|
||||
days = 30 - (hebrewMonth - 1) % 2;
|
||||
}
|
||||
if (hebrewDay <= days) {
|
||||
// In the current month
|
||||
break;
|
||||
} else {
|
||||
// Subtract the days of the current month
|
||||
hebrewDay -= days;
|
||||
// Try in the next month
|
||||
hebrewMonth++;
|
||||
}
|
||||
}
|
||||
rv[0] = hebrewYear;
|
||||
rv[1] = hebrewMonth;
|
||||
rv[2] = hebrewDay;
|
||||
rv[3] = days;
|
||||
return true;
|
||||
}
|
||||
public static byte[] Get_hebrew_month_name_full(Xowe_wiki wiki, DateAdp date) {return Get_hebrew_month_name(wiki, date, Month_name_full_ary);}
|
||||
public static byte[] Get_hebrew_month_name_gen(Xowe_wiki wiki, DateAdp date) {return Get_hebrew_month_name(wiki, date, Month_name_gen_ary);}
|
||||
private static byte[] Get_hebrew_month_name(Xowe_wiki wiki, DateAdp date, byte[][] name_ary) {
|
||||
int[] hebrew_date = Pft_fmt_itm_hebrew_.Calc_hebrew_date(date);
|
||||
int hebrew_month = hebrew_date[Pft_fmt_itm_hebrew_.Rslt_month_num] - List_adp_.Base1;
|
||||
byte[] msg_key = name_ary[hebrew_month];
|
||||
return wiki.Msg_mgr().Val_by_key_obj(msg_key);
|
||||
}
|
||||
private static final byte[][] Month_name_full_ary = new byte[][]
|
||||
{ Bry_.new_a7("hebrew-calendar-m1"), Bry_.new_a7("hebrew-calendar-m2"), Bry_.new_a7("hebrew-calendar-m3")
|
||||
, Bry_.new_a7("hebrew-calendar-m4"), Bry_.new_a7("hebrew-calendar-m5"), Bry_.new_a7("hebrew-calendar-m6")
|
||||
, Bry_.new_a7("hebrew-calendar-m7"), Bry_.new_a7("hebrew-calendar-m8"), Bry_.new_a7("hebrew-calendar-m9")
|
||||
, Bry_.new_a7("hebrew-calendar-m10"), Bry_.new_a7("hebrew-calendar-m11"), Bry_.new_a7("hebrew-calendar-m12")
|
||||
, Bry_.new_a7("hebrew-calendar-m6a"), Bry_.new_a7("hebrew-calendar-m6b")
|
||||
};
|
||||
private static final byte[][] Month_name_gen_ary = new byte[][]
|
||||
{ Bry_.new_a7("hebrew-calendar-m1-gen"), Bry_.new_a7("hebrew-calendar-m2-gen"), Bry_.new_a7("hebrew-calendar-m3-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m4-gen"), Bry_.new_a7("hebrew-calendar-m5-gen"), Bry_.new_a7("hebrew-calendar-m6-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m7-gen"), Bry_.new_a7("hebrew-calendar-m8-gen"), Bry_.new_a7("hebrew-calendar-m9-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m10-gen"), Bry_.new_a7("hebrew-calendar-m11-gen"), Bry_.new_a7("hebrew-calendar-m12-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m6a-gen"), Bry_.new_a7("hebrew-calendar-m6b-gen")
|
||||
};
|
||||
public static final int
|
||||
Rslt_year_num = 0
|
||||
, Rslt_month_num = 1
|
||||
, Rslt_day_num = 2
|
||||
, Rslt_month_days_count = 3
|
||||
;
|
||||
|
||||
private static final String[][] Numeral_tbls = new String[][]
|
||||
{ new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
|
||||
, new String[] {"", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ", "ק"}
|
||||
, new String[] {"", "ק", "ר", "ש", "ת", "תק", "תר", "תש", "תת", "תתק", "תתר"}
|
||||
, new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
|
||||
};
|
||||
public static String Calc_hebrew_numeral(int num) {
|
||||
if (num > 9999 || num <= 0)
|
||||
return Int_.Xto_str(num);
|
||||
|
||||
String tmp = "";
|
||||
int pow10 = 1000;
|
||||
for (int i = 3; i >= 0; pow10 /= 10, i--) {
|
||||
if (num >= pow10) {
|
||||
if (num == 15 || num == 16) {
|
||||
tmp += Numeral_tbls[0][9] + Numeral_tbls[0][num - 9];
|
||||
num = 0;
|
||||
} else {
|
||||
tmp += Numeral_tbls[i][(int)(num / pow10)];
|
||||
if (pow10 == 1000)
|
||||
tmp += "'";
|
||||
}
|
||||
}
|
||||
num = num % pow10;
|
||||
}
|
||||
String rv = "";
|
||||
int tmp_len = String_.Len(tmp);
|
||||
if (tmp_len == 2) {
|
||||
rv = tmp + "'";
|
||||
}
|
||||
else {
|
||||
rv = String_.Mid(tmp, 0, tmp_len - 1) + "\"";
|
||||
rv += String_.Mid(tmp, tmp_len - 1);
|
||||
}
|
||||
int rv_len = String_.Len(rv);
|
||||
String start = String_.Mid(rv, 0, rv_len - 1);
|
||||
String end = String_.Mid(rv, rv_len - 1);
|
||||
if (String_.Eq(end, "כ"))
|
||||
rv = start + "ך";
|
||||
else if (String_.Eq(end, "מ"))
|
||||
rv = start + "ם";
|
||||
else if (String_.Eq(end, "נ"))
|
||||
rv = start + "ן";
|
||||
else if (String_.Eq(end, "פ"))
|
||||
rv = start + "ף";
|
||||
else if (String_.Eq(end, "צ"))
|
||||
rv = start + "ץ";
|
||||
return rv;
|
||||
class Pft_fmt_itm_iranian_year_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_iranian_year_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_iranian.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_iranian.Rslt__year]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_iranian_month_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_iranian_month_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_iranian.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_iranian.Rslt__month]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_iranian_day_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_iranian_day_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_iranian.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_iranian.Rslt__day]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_iranian_month_name implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_iranian_month_name;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
bfr.Add(Pft_fmt_itm_iranian.Get_month_name(wiki, date));
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hijiri_year_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_hijiri_year_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_hijiri.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_hijiri.Rslt__year]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hijiri_month_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_hijiri_month_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_hijiri.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_hijiri.Rslt__month]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hijiri_day_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_hijiri_day_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_hijiri.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_hijiri.Rslt__day]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hijiri_month_name implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_hijiri_month_name;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
bfr.Add(Pft_fmt_itm_hijiri.Get_month_name(wiki, date));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
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.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
class Pft_fmt_itm_hebrew_ {
|
||||
public static int Calc_hebrew_year_num_start(int year) {
|
||||
int year_minus_1 = year - 1;
|
||||
int a = (12 * year_minus_1 + 17) % 19;
|
||||
int b = year_minus_1 % 4;
|
||||
double m = 32.044093161144d + 1.5542417966212d * a + b / 4.0 - 0.0031777940220923d * year_minus_1;
|
||||
if (m < 0)
|
||||
m--;
|
||||
int mar = (int)m;
|
||||
if (m < 0)
|
||||
m++;
|
||||
m -= mar;
|
||||
int c = (mar + 3 * year_minus_1 + 5 * b + 5) % 7;
|
||||
if (c == 0 && a > 11 && m >= 0.89772376543210d)
|
||||
mar++;
|
||||
else if (c == 1 && a > 6 && m >= 0.63287037037037d)
|
||||
mar += 2;
|
||||
else if (c == 2 || c == 4 || c == 6)
|
||||
mar++;
|
||||
double year_minus_3761 = year - 3761;
|
||||
mar += (int)(year_minus_3761 / 100 ) - (int)(year_minus_3761 / 400) - 24;
|
||||
return mar;
|
||||
}
|
||||
private static final int[] Hebrew_date_rslt = new int[4];
|
||||
public static int[] Calc_hebrew_date(DateAdp date) {
|
||||
synchronized (Hebrew_date_rslt) {
|
||||
Calc_hebrew_date(Hebrew_date_rslt, date.Year(), date.Month(), date.Day());
|
||||
return Hebrew_date_rslt;
|
||||
}
|
||||
}
|
||||
public static boolean Calc_hebrew_date(int[] rv, int year, int month, int day) { // REF.MW:Language.php|tsToHebrew
|
||||
// Calculate Hebrew year
|
||||
int hebrewYear = year + 3760;
|
||||
|
||||
// Month number when September = 1, August = 12
|
||||
month += 4;
|
||||
if (month > 12) {
|
||||
// Next year
|
||||
month -= 12;
|
||||
year++;
|
||||
hebrewYear++;
|
||||
}
|
||||
|
||||
// Calculate day of year from 1 September
|
||||
int dayOfYear = day;
|
||||
for (int i = 1; i < month; i++) {
|
||||
if (i == 6) {
|
||||
// February
|
||||
dayOfYear += 28;
|
||||
// Check if the year is leap
|
||||
if (year % 400 == 0 || (year % 4 == 0 && year % 100 > 0)) {
|
||||
dayOfYear++;
|
||||
}
|
||||
} else if (i == 8 || i == 10 || i == 1 || i == 3) {
|
||||
dayOfYear += 30;
|
||||
} else {
|
||||
dayOfYear += 31;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the start of the Hebrew year
|
||||
int start = Calc_hebrew_year_num_start(hebrewYear);
|
||||
|
||||
// Calculate next year's start
|
||||
int nextStart = 0;
|
||||
if (dayOfYear <= start) {
|
||||
// Day is before the start of the year - it is the previous year
|
||||
// Next year's start
|
||||
nextStart = start;
|
||||
// Previous year
|
||||
year--;
|
||||
hebrewYear--;
|
||||
// Add days since previous year's 1 September
|
||||
dayOfYear += 365;
|
||||
if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
|
||||
// Leap year
|
||||
dayOfYear++;
|
||||
}
|
||||
// Start of the new (previous) year
|
||||
start = Calc_hebrew_year_num_start(hebrewYear);
|
||||
} else {
|
||||
// Next year's start
|
||||
nextStart = Calc_hebrew_year_num_start(hebrewYear + 1);
|
||||
}
|
||||
|
||||
// Calculate Hebrew day of year
|
||||
int hebrewDayOfYear = dayOfYear - start;
|
||||
|
||||
// Difference between year's days
|
||||
int diff = nextStart - start;
|
||||
// Add 12 (or 13 for leap years) days to ignore the difference between
|
||||
// Hebrew and Gregorian year (353 at least vs. 365/6) - now the
|
||||
// difference is only about the year type
|
||||
if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
|
||||
diff += 13;
|
||||
} else {
|
||||
diff += 12;
|
||||
}
|
||||
|
||||
// Check the year pattern, and is leap year
|
||||
// 0 means an incomplete year, 1 means a regular year, 2 means a complete year
|
||||
// This is mod 30, to work on both leap years (which add 30 days of Adar I)
|
||||
// and non-leap years
|
||||
int yearPattern = diff % 30;
|
||||
// Check if leap year
|
||||
boolean isLeap = diff >= 30;
|
||||
|
||||
// Calculate day in the month from number of day in the Hebrew year
|
||||
// Don't check Adar - if the day is not in Adar, we will stop before;
|
||||
// if it is in Adar, we will use it to check if it is Adar I or Adar II
|
||||
int hebrewDay = hebrewDayOfYear;
|
||||
int hebrewMonth = 1;
|
||||
int days = 0;
|
||||
|
||||
while (hebrewMonth <= 12) {
|
||||
// Calculate days in this month
|
||||
if (isLeap && hebrewMonth == 6) {
|
||||
// Adar in a leap year
|
||||
if (isLeap) {
|
||||
// Leap year - has Adar I, with 30 days, and Adar II, with 29 days
|
||||
days = 30;
|
||||
if (hebrewDay <= days) {
|
||||
// Day in Adar I
|
||||
hebrewMonth = 13;
|
||||
} else {
|
||||
// Subtract the days of Adar I
|
||||
hebrewDay -= days;
|
||||
// Try Adar II
|
||||
days = 29;
|
||||
if (hebrewDay <= days) {
|
||||
// Day in Adar II
|
||||
hebrewMonth = 14;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (hebrewMonth == 2 && yearPattern == 2) {
|
||||
// Cheshvan in a complete year (otherwise as the rule below)
|
||||
days = 30;
|
||||
} else if (hebrewMonth == 3 && yearPattern == 0) {
|
||||
// Kislev in an incomplete year (otherwise as the rule below)
|
||||
days = 29;
|
||||
} else {
|
||||
// Odd months have 30 days, even have 29
|
||||
days = 30 - (hebrewMonth - 1) % 2;
|
||||
}
|
||||
if (hebrewDay <= days) {
|
||||
// In the current month
|
||||
break;
|
||||
} else {
|
||||
// Subtract the days of the current month
|
||||
hebrewDay -= days;
|
||||
// Try in the next month
|
||||
hebrewMonth++;
|
||||
}
|
||||
}
|
||||
rv[0] = hebrewYear;
|
||||
rv[1] = hebrewMonth;
|
||||
rv[2] = hebrewDay;
|
||||
rv[3] = days;
|
||||
return true;
|
||||
}
|
||||
public static byte[] Get_hebrew_month_name_full(Xowe_wiki wiki, DateAdp date) {return Get_hebrew_month_name(wiki, date, Month_name_full_ary);}
|
||||
public static byte[] Get_hebrew_month_name_gen(Xowe_wiki wiki, DateAdp date) {return Get_hebrew_month_name(wiki, date, Month_name_gen_ary);}
|
||||
private static byte[] Get_hebrew_month_name(Xowe_wiki wiki, DateAdp date, byte[][] name_ary) {
|
||||
int[] hebrew_date = Pft_fmt_itm_hebrew_.Calc_hebrew_date(date);
|
||||
int hebrew_month = hebrew_date[Pft_fmt_itm_hebrew_.Rslt_month_num] - List_adp_.Base1;
|
||||
byte[] msg_key = name_ary[hebrew_month];
|
||||
return wiki.Msg_mgr().Val_by_key_obj(msg_key);
|
||||
}
|
||||
private static final byte[][] Month_name_full_ary = new byte[][]
|
||||
{ Bry_.new_a7("hebrew-calendar-m1"), Bry_.new_a7("hebrew-calendar-m2"), Bry_.new_a7("hebrew-calendar-m3")
|
||||
, Bry_.new_a7("hebrew-calendar-m4"), Bry_.new_a7("hebrew-calendar-m5"), Bry_.new_a7("hebrew-calendar-m6")
|
||||
, Bry_.new_a7("hebrew-calendar-m7"), Bry_.new_a7("hebrew-calendar-m8"), Bry_.new_a7("hebrew-calendar-m9")
|
||||
, Bry_.new_a7("hebrew-calendar-m10"), Bry_.new_a7("hebrew-calendar-m11"), Bry_.new_a7("hebrew-calendar-m12")
|
||||
, Bry_.new_a7("hebrew-calendar-m6a"), Bry_.new_a7("hebrew-calendar-m6b")
|
||||
};
|
||||
private static final byte[][] Month_name_gen_ary = new byte[][]
|
||||
{ Bry_.new_a7("hebrew-calendar-m1-gen"), Bry_.new_a7("hebrew-calendar-m2-gen"), Bry_.new_a7("hebrew-calendar-m3-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m4-gen"), Bry_.new_a7("hebrew-calendar-m5-gen"), Bry_.new_a7("hebrew-calendar-m6-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m7-gen"), Bry_.new_a7("hebrew-calendar-m8-gen"), Bry_.new_a7("hebrew-calendar-m9-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m10-gen"), Bry_.new_a7("hebrew-calendar-m11-gen"), Bry_.new_a7("hebrew-calendar-m12-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m6a-gen"), Bry_.new_a7("hebrew-calendar-m6b-gen")
|
||||
};
|
||||
public static final int
|
||||
Rslt_year_num = 0
|
||||
, Rslt_month_num = 1
|
||||
, Rslt_day_num = 2
|
||||
, Rslt_month_days_count = 3
|
||||
;
|
||||
|
||||
private static final String[][] Numeral_tbls = new String[][]
|
||||
{ new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
|
||||
, new String[] {"", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ", "ק"}
|
||||
, new String[] {"", "ק", "ר", "ש", "ת", "תק", "תר", "תש", "תת", "תתק", "תתר"}
|
||||
, new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
|
||||
};
|
||||
public static String Calc_hebrew_numeral(int num) {
|
||||
if (num > 9999 || num <= 0)
|
||||
return Int_.Xto_str(num);
|
||||
|
||||
String tmp = "";
|
||||
int pow10 = 1000;
|
||||
for (int i = 3; i >= 0; pow10 /= 10, i--) {
|
||||
if (num >= pow10) {
|
||||
if (num == 15 || num == 16) {
|
||||
tmp += Numeral_tbls[0][9] + Numeral_tbls[0][num - 9];
|
||||
num = 0;
|
||||
} else {
|
||||
tmp += Numeral_tbls[i][(int)(num / pow10)];
|
||||
if (pow10 == 1000)
|
||||
tmp += "'";
|
||||
}
|
||||
}
|
||||
num = num % pow10;
|
||||
}
|
||||
String rv = "";
|
||||
int tmp_len = String_.Len(tmp);
|
||||
if (tmp_len == 2) {
|
||||
rv = tmp + "'";
|
||||
}
|
||||
else {
|
||||
rv = String_.Mid(tmp, 0, tmp_len - 1) + "\"";
|
||||
rv += String_.Mid(tmp, tmp_len - 1);
|
||||
}
|
||||
int rv_len = String_.Len(rv);
|
||||
String start = String_.Mid(rv, 0, rv_len - 1);
|
||||
String end = String_.Mid(rv, rv_len - 1);
|
||||
if (String_.Eq(end, "כ"))
|
||||
rv = start + "ך";
|
||||
else if (String_.Eq(end, "מ"))
|
||||
rv = start + "ם";
|
||||
else if (String_.Eq(end, "נ"))
|
||||
rv = start + "ן";
|
||||
else if (String_.Eq(end, "פ"))
|
||||
rv = start + "ף";
|
||||
else if (String_.Eq(end, "צ"))
|
||||
rv = start + "ץ";
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
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.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
class Pft_fmt_itm_hijiri {
|
||||
private static final int[] tmp_rslt = new int[3];
|
||||
public static int[] Calc_date(DateAdp date) {
|
||||
synchronized (tmp_rslt) {
|
||||
Calc_date(tmp_rslt, date.Year(), date.Month(), date.Day());
|
||||
return tmp_rslt;
|
||||
}
|
||||
}
|
||||
public static boolean Calc_date(int[] rv, int greg_y, int greg_m, int greg_d) {
|
||||
int hiji_d = greg_d;
|
||||
int hiji_m = greg_m;
|
||||
int hiji_y = greg_y;
|
||||
|
||||
int tmp_jd = 0;
|
||||
if (
|
||||
(hiji_y > 1582) || ((hiji_y == 1582) && (hiji_m > 10)) ||
|
||||
((hiji_y == 1582) && (hiji_m == 10) && (hiji_d > 14))
|
||||
)
|
||||
{
|
||||
tmp_jd = (int)((1461 * (hiji_y + 4800 + (int)((hiji_m - 14) / 12))) / 4) +
|
||||
(int)((367 * (hiji_m - 2 - 12 * ((int)((hiji_m - 14) / 12)))) / 12) -
|
||||
(int)((3 * (int)(((hiji_y + 4900 + (int)((hiji_m - 14) / 12)) / 100))) / 4) +
|
||||
hiji_d - 32075;
|
||||
} else {
|
||||
tmp_jd = 367 * hiji_y - (int)((7 * (hiji_y + 5001 + (int)((hiji_m - 9) / 7))) / 4) +
|
||||
(int)((275 * hiji_m) / 9) + hiji_d + 1729777;
|
||||
}
|
||||
|
||||
int tmp_l = tmp_jd -1948440 + 10632;
|
||||
int tmp_n = (int)((tmp_l - 1) / 10631);
|
||||
tmp_l = tmp_l - 10631 * tmp_n + 354;
|
||||
int tmp_j = ((int)((10985 - tmp_l) / 5316)) * ((int)((50 * tmp_l) / 17719)) + ((int)(tmp_l / 5670)) * ((int)((43 * tmp_l) / 15238));
|
||||
tmp_l = tmp_l - ((int)((30 - tmp_j) / 15)) * ((int)((17719 * tmp_j) / 50)) - ((int)(tmp_j / 16)) * ((int)((15238 * tmp_j) / 43)) + 29;
|
||||
hiji_m = (int)((24 * tmp_l) / 709);
|
||||
hiji_d = tmp_l - (int)((709 * hiji_m) / 24);
|
||||
hiji_y = 30 * tmp_n + tmp_j - 30;
|
||||
|
||||
rv[0] = hiji_y;
|
||||
rv[1] = hiji_m;
|
||||
rv[2] = hiji_d;
|
||||
return true;
|
||||
}
|
||||
public static byte[] Get_month_name(Xowe_wiki wiki, DateAdp date) {
|
||||
int[] seg_ary = Calc_date(date);
|
||||
int m = seg_ary[Rslt__month] - List_adp_.Base1;
|
||||
byte[] msg_key = Month_names[m];
|
||||
return wiki.Msg_mgr().Val_by_key_obj(msg_key);
|
||||
}
|
||||
private static final byte[][] Month_names = new byte[][]
|
||||
{ Bry_.new_a7("hijiri-calendar-m1"), Bry_.new_a7("hijiri-calendar-m2"), Bry_.new_a7("hijiri-calendar-m3")
|
||||
, Bry_.new_a7("hijiri-calendar-m4"), Bry_.new_a7("hijiri-calendar-m5"), Bry_.new_a7("hijiri-calendar-m6")
|
||||
, Bry_.new_a7("hijiri-calendar-m7"), Bry_.new_a7("hijiri-calendar-m8"), Bry_.new_a7("hijiri-calendar-m9")
|
||||
, Bry_.new_a7("hijiri-calendar-m10"), Bry_.new_a7("hijiri-calendar-m11"), Bry_.new_a7("hijiri-calendar-m12")
|
||||
};
|
||||
public static final int
|
||||
Rslt__year = 0
|
||||
, Rslt__month = 1
|
||||
, Rslt__day = 2
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
class Pft_fmt_itm_iranian {
|
||||
private static final int[] Md__greg = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
private static final int[] Md__iran = new int[] { 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 };
|
||||
private static final int[] tmp_rslt = new int[3];
|
||||
public static int[] Calc_date(DateAdp date) {
|
||||
synchronized (Md__iran) {
|
||||
Calc_date(tmp_rslt, date.Year(), date.Month(), date.Day());
|
||||
return tmp_rslt;
|
||||
}
|
||||
}
|
||||
public static boolean Calc_date(int[] rv, int greg_y, int greg_m, int greg_d) { // REF.MW:Language.php|tsToIranian
|
||||
greg_y -= 1600;
|
||||
--greg_m;
|
||||
--greg_d;
|
||||
|
||||
// Days passed from the beginning (including leap years)
|
||||
int greg_doy = 365 * greg_y
|
||||
+ (int)((greg_y + 3) / 4)
|
||||
- (int)((greg_y + 99) / 100)
|
||||
+ (int)((greg_y + 399) / 400)
|
||||
;
|
||||
|
||||
// Add days of the past months of this year
|
||||
for (int i = 0; i < greg_m; ++i) {
|
||||
greg_doy += Md__greg[i];
|
||||
}
|
||||
|
||||
// Leap years
|
||||
if (greg_m > 1 && ((greg_y % 4 == 0 && greg_y % 100 != 0 || (greg_y % 400 == 0))))
|
||||
greg_doy++;
|
||||
|
||||
// Days passed in current month
|
||||
greg_doy += greg_d;
|
||||
|
||||
int iran_doy = greg_doy - 79;
|
||||
|
||||
int iran_np = (int)(iran_doy / 12053);
|
||||
iran_doy %= 12053;
|
||||
|
||||
int iran_y = 979 + 33 * iran_np + 4 * (int)(iran_doy / 1461);
|
||||
iran_doy %= 1461;
|
||||
|
||||
if (iran_doy >= 366) {
|
||||
iran_y += (int)((iran_doy - 1) / 365);
|
||||
iran_doy = (int)((iran_doy - 1) % 365);
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (j = 0; j < 11 && iran_doy >= Md__iran[j]; ++j)
|
||||
iran_doy -= Md__iran[j];
|
||||
|
||||
int iran_m = j + 1;
|
||||
int iran_d = iran_doy + 1;
|
||||
|
||||
rv[0] = iran_y;
|
||||
rv[1] = iran_m;
|
||||
rv[2] = iran_d;
|
||||
return true;
|
||||
}
|
||||
public static byte[] Get_month_name(Xowe_wiki wiki, DateAdp date) {
|
||||
int[] seg_ary = Calc_date(date);
|
||||
int m = seg_ary[Rslt__month] - List_adp_.Base1;
|
||||
byte[] msg_key = Month_names[m];
|
||||
return wiki.Msg_mgr().Val_by_key_obj(msg_key);
|
||||
}
|
||||
private static final byte[][] Month_names = new byte[][]
|
||||
{ Bry_.new_a7("iranian-calendar-m1"), Bry_.new_a7("iranian-calendar-m2"), Bry_.new_a7("iranian-calendar-m3")
|
||||
, Bry_.new_a7("iranian-calendar-m4"), Bry_.new_a7("iranian-calendar-m5"), Bry_.new_a7("iranian-calendar-m6")
|
||||
, Bry_.new_a7("iranian-calendar-m7"), Bry_.new_a7("iranian-calendar-m8"), Bry_.new_a7("iranian-calendar-m9")
|
||||
, Bry_.new_a7("iranian-calendar-m10"), Bry_.new_a7("iranian-calendar-m11"), Bry_.new_a7("iranian-calendar-m12")
|
||||
};
|
||||
public static final int
|
||||
Rslt__year = 0
|
||||
, Rslt__month = 1
|
||||
, Rslt__day = 2
|
||||
;
|
||||
}
|
||||
@@ -20,18 +20,26 @@ import org.junit.*;
|
||||
public class Pft_func_time_foreign_tst {
|
||||
@Before public void init() {fxt.Clear();} private Pft_func_time_foreign_fxt fxt = new Pft_func_time_foreign_fxt();
|
||||
@After public void term() {fxt.Term();}
|
||||
@Test public void Roman() {fxt.Test_parse("{{#time:xrY|2012}}" , "MMXII");}
|
||||
@Test public void Thai() {fxt.Test_parse("{{#time:xkY|2012}}" , "2555");}
|
||||
@Test public void Minguo() {fxt.Test_parse("{{#time:xoY|2012}}" , "101");}
|
||||
@Test public void Hebrew_year_num() {fxt.Test_parse("{{#time:xjY|2012-01-02}}" , "5772");}
|
||||
@Test public void Hebrew_month_num() {fxt.Test_parse("{{#time:xjn|2012-01-02}}" , "4");}
|
||||
@Test public void Hebrew_day_num() {fxt.Test_parse("{{#time:xjj|2012-01-02}}" , "7");}
|
||||
@Test public void Hebrew_month_days_count() {fxt.Test_parse("{{#time:xjt|2012-01-02}}" , "29");}
|
||||
@Test public void Hebrew_month_name_full() {fxt.Init_msg("hebrew-calendar-m4" , "Tevet").Test_parse("{{#time:xjF|2012-01-02}}" , "Tevet");}
|
||||
@Test public void Hebrew_month_name_gen() {fxt.Init_msg("hebrew-calendar-m4-gen" , "Tevet").Test_parse("{{#time:xjx|2012-01-02}}" , "Tevet");}
|
||||
@Test public void Hebrew_numeral() {fxt.Test_parse("{{#time:xh}}" , "");}
|
||||
@Test public void Hebrew_numeral_2() {fxt.Test_parse("{{#time:xhxjY|2014}}" , "ה'תשע\"ד");}
|
||||
@Test public void Roman_various() {
|
||||
@Test public void Hebrew__year_num() {fxt.Test_parse("{{#time:xjY|2012-01-02}}" , "5772");}
|
||||
@Test public void Hebrew__month_num() {fxt.Test_parse("{{#time:xjn|2012-01-02}}" , "4");}
|
||||
@Test public void Hebrew__day_num() {fxt.Test_parse("{{#time:xjj|2012-01-02}}" , "7");}
|
||||
@Test public void Hebrew__month_days_count() {fxt.Test_parse("{{#time:xjt|2012-01-02}}" , "29");}
|
||||
@Test public void Hebrew__month_name_full() {fxt.Init_msg("hebrew-calendar-m4" , "Tevet").Test_parse("{{#time:xjF|2012-01-02}}" , "Tevet");}
|
||||
@Test public void Hebrew__month_name_gen() {fxt.Init_msg("hebrew-calendar-m4-gen" , "Tevet").Test_parse("{{#time:xjx|2012-01-02}}" , "Tevet");}
|
||||
@Test public void Hebrew__numeral() {fxt.Test_parse("{{#time:xh}}" , "");}
|
||||
@Test public void Hebrew__numeral_2() {fxt.Test_parse("{{#time:xhxjY|2014}}" , "ה'תשע\"ד");}
|
||||
@Test public void Iranian__year_idx() {fxt.Test_parse("{{#time:xiY|2012-01-02}}" , "1390");}
|
||||
@Test public void Iranian__month_idx() {fxt.Test_parse("{{#time:xin|2012-01-02}}" , "10");}
|
||||
@Test public void Iranian__day_idx() {fxt.Test_parse("{{#time:xij|2012-01-02}}" , "12");}
|
||||
@Test public void Iranian__month_name() {fxt.Init_msg("iranian-calendar-m10" , "Dey"); fxt.Test_parse("{{#time:xiF|2012-01-02}}" , "Dey");}
|
||||
@Test public void Hijiri__year_idx() {fxt.Test_parse("{{#time:xmY|2012-01-02}}" , "1433");}
|
||||
@Test public void Hijiri__month_idx() {fxt.Test_parse("{{#time:xmn|2012-01-02}}" , "2");}
|
||||
@Test public void Hijiri__day_idx() {fxt.Test_parse("{{#time:xmj|2012-01-02}}" , "7");}
|
||||
@Test public void Hijiri__month_name() {fxt.Init_msg("hijiri-calendar-m2" , "Safar"); fxt.Test_parse("{{#time:xmF|2012-01-02}}" , "Safar");}
|
||||
@Test public void Roman__year() {fxt.Test_parse("{{#time:xrY|2012}}" , "MMXII");}
|
||||
@Test public void Roman__various() {
|
||||
fxt.Test_Roman( 1, "I");
|
||||
fxt.Test_Roman( 2, "II");
|
||||
fxt.Test_Roman( 3, "III");
|
||||
|
||||
@@ -85,21 +85,21 @@ class Pxd_itm_sym extends Pxd_itm_base {
|
||||
}
|
||||
class Pxd_itm_int_dmy_14 extends Pxd_itm_base implements Pxd_itm_int_interface {
|
||||
public Pxd_itm_int_dmy_14(int ary_idx, byte[] src, int digits) {this.Ctor(ary_idx); this.src = src; this.digits = digits;} private byte[] src; int digits;
|
||||
public int Xto_int_or(int or) {return Bry_.Xto_int_or(src, or);}
|
||||
public int Xto_int_or(int or) {return Bry_.To_int_or(src, or);}
|
||||
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_int_dmy_14;}
|
||||
@Override public int Eval_idx() {return eval_idx;} private int eval_idx = 20;
|
||||
@Override public void Time_ini(DateAdpBldr bldr) {
|
||||
if (this.Seg_idx() != Pxd_itm_base.Seg_idx_null) return; // has seg_idx; already eval'd by something else
|
||||
bldr.Seg_set(DateAdp_.SegIdx_year , Bry_.Xto_int_or(src, 0, 4, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_month , Bry_.Xto_int_or(src, 4, 6, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_year , Bry_.To_int_or(src, 0, 4, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_month , Bry_.To_int_or(src, 4, 6, 0));
|
||||
if (digits > 6) {
|
||||
bldr.Seg_set(DateAdp_.SegIdx_day , Bry_.Xto_int_or(src, 6, 8, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_day , Bry_.To_int_or(src, 6, 8, 0));
|
||||
if (digits > 8) {
|
||||
bldr.Seg_set(DateAdp_.SegIdx_hour , Bry_.Xto_int_or(src, 8, 10, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_hour , Bry_.To_int_or(src, 8, 10, 0));
|
||||
if (digits > 10) {
|
||||
bldr.Seg_set(DateAdp_.SegIdx_minute , Bry_.Xto_int_or(src, 10, 12, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_minute , Bry_.To_int_or(src, 10, 12, 0));
|
||||
if (digits > 12)
|
||||
bldr.Seg_set(DateAdp_.SegIdx_second , Bry_.Xto_int_or(src, 12, 14, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_second , Bry_.To_int_or(src, 12, 14, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,14 +107,14 @@ class Pxd_itm_int_dmy_14 extends Pxd_itm_base implements Pxd_itm_int_interface {
|
||||
}
|
||||
class Pxd_itm_int_mhs_6 extends Pxd_itm_base implements Pxd_itm_int_interface {
|
||||
public Pxd_itm_int_mhs_6(int ary_idx, byte[] src) {this.Ctor(ary_idx); this.src = src;} private byte[] src;
|
||||
public int Xto_int_or(int or) {return Bry_.Xto_int_or(src, or);}
|
||||
public int Xto_int_or(int or) {return Bry_.To_int_or(src, or);}
|
||||
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_int_hms_6;}
|
||||
@Override public int Eval_idx() {return eval_idx;} private int eval_idx = 20;
|
||||
@Override public void Time_ini(DateAdpBldr bldr) {
|
||||
if (this.Seg_idx() != Pxd_itm_base.Seg_idx_null) return; // has seg_idx; already eval'd by something else
|
||||
bldr.Seg_set(DateAdp_.SegIdx_hour , Bry_.Xto_int_or(src, 0, 2, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_minute , Bry_.Xto_int_or(src, 2, 4, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_second , Bry_.Xto_int_or(src, 4, 6, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_hour , Bry_.To_int_or(src, 0, 2, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_minute , Bry_.To_int_or(src, 2, 4, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_second , Bry_.To_int_or(src, 4, 6, 0));
|
||||
}
|
||||
}
|
||||
class Pxd_itm_sorter implements gplx.lists.ComparerAble {
|
||||
|
||||
@@ -98,12 +98,13 @@ class Pxd_parser {
|
||||
Pxd_itm itm = null;
|
||||
switch (tkn_type) {
|
||||
case Pxd_itm_.Tid_int:
|
||||
int int_val = Bry_.Xto_int_or(src, tkn_bgn_pos, cur_pos, Int_.MinValue);
|
||||
int int_val = Bry_.To_int_or(src, tkn_bgn_pos, cur_pos, Int_.MinValue);
|
||||
if (int_val == Int_.MinValue) {} // FUTURE: warn
|
||||
int digits = cur_pos - tkn_bgn_pos;
|
||||
switch (digits) {
|
||||
case 14:
|
||||
case 8:
|
||||
case 14: // yyyyMMddhhmmss
|
||||
case 12: // yyyyMMddhhmm; PAGE:en.w:Boron; DATE:2015-07-29
|
||||
case 8: // yyyyMMdd
|
||||
itm = new Pxd_itm_int_dmy_14(tkns_len, Bry_.Mid(src, tkn_bgn_pos, cur_pos), digits); break;
|
||||
case 6:
|
||||
itm = new Pxd_itm_int_mhs_6(tkns_len, Bry_.Mid(src, tkn_bgn_pos, cur_pos)); break;
|
||||
@@ -164,7 +165,7 @@ class Pxd_parser {
|
||||
class Pxd_parser_ {
|
||||
public static Btrie_slim_mgr Trie() {
|
||||
if (trie == null) {
|
||||
trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en
|
||||
trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en
|
||||
Init();
|
||||
}
|
||||
return trie;
|
||||
|
||||
@@ -56,6 +56,7 @@ public class Pxd_parser_tst {
|
||||
@Test public void Unit_day_neg_w_day() {tst_date_("30 May 2012 -1 days" , "2012-05-29");} // PAGE:en.w:Main Page
|
||||
@Test public void Unit_week() {tst_date_("- 1 week" , "2012-02-26");} // PURPOSE.FIX: "week" was not being handled; error on main Page; EX:da.wikipedia.org/Main_Page
|
||||
@Test public void Time_len_6() {tst_time_("041526" , "04:15:26.000");}
|
||||
@Test public void Time_len_12() {tst_both_("201601020304" , "2016-01-02 03:04:00.000");} // PURPOSE: handle 12 digit datetime; PAGE:en.w:Boron; DATE:2015-07-29
|
||||
@Test public void Err_one_num() {tst_time_("2" , "Invalid year: 2");} // occurs on some templates; PAGE:en.w:Voyager 1 and {{date}}
|
||||
@Test public void Dmy_at_y_dot() {tst_date_("1.2.70" , "1970-02-01");} // PURPOSE: dmy when delimiter is dot
|
||||
@Test public void Mdy_at_y_slash() {tst_date_("1/2/70" , "1970-01-02");} // PURPOSE: mdy when delimiter is slash
|
||||
|
||||
Reference in New Issue
Block a user