[Libreoffice-commits] core.git: i18npool/source svl/source

2021-09-29 Thread Eike Rathke (via logerrit)
 i18npool/source/calendar/calendar_gregorian.cxx |   53 
 svl/source/numbers/zforlist.cxx |   20 -
 svl/source/numbers/zformat.cxx  |   32 --
 3 files changed, 83 insertions(+), 22 deletions(-)

New commits:
commit ebc454ad4eb1f4cd4d84a7db367bb71a457c4e5c
Author: Eike Rathke 
AuthorDate: Wed Sep 29 23:14:18 2021 +0200
Commit: Eike Rathke 
CommitDate: Thu Sep 30 02:04:01 2021 +0200

Resolves: tdf#144697 Format out-of-bounds date(+time) as #FMT error

i.e. < -32768-01-01 or > 32767-12-31
They couldn't be input or stored as proleptic Gregorian in file
formats anyway.

Additionally in i18npool handle the absolute year values casting
conversion int32 <-> int16 where era 0 BCE year 32768 is fielded as
-32768 but still is a valid year for our proleptic Gregorian, so
it isn't displayed as --32768.

Change-Id: Ifdd482f07e04c2a4296fd0556bbef7f1d3e15676
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122835
Reviewed-by: Eike Rathke 
Tested-by: Jenkins

diff --git a/i18npool/source/calendar/calendar_gregorian.cxx 
b/i18npool/source/calendar/calendar_gregorian.cxx
index 6a1dad685309..df998b3c6cf3 100644
--- a/i18npool/source/calendar/calendar_gregorian.cxx
+++ b/i18npool/source/calendar/calendar_gregorian.cxx
@@ -127,6 +127,22 @@ using namespace ::com::sun::star::lang;
 
 namespace i18npool {
 
+// Cast positive int32 values to signed int16, needed for
+// fieldValue[CalendarFieldIndex::YEAR] where absolute value of an era year may
+// be 32768 that with static_cast becomes -32768, which we also
+// do here but indicating places in a controlled way to map back.
+static inline sal_Int16 cast32To16( sal_Int32 a )
+{
+// More than uint16 can't be handled, should not occur.
+assert(a >= 0 && a < static_cast(SAL_MAX_INT16) - 
static_cast(SAL_MIN_INT16));
+return static_cast(a);
+}
+// And back.
+static inline sal_Int32 cast16To32( sal_Int16 i )
+{
+return static_cast(static_cast(i));
+}
+
 Calendar_gregorian::Calendar_gregorian()
 : mxNatNum(new NativeNumberSupplierService)
 {
@@ -409,10 +425,11 @@ void Calendar_gregorian::mapFromGregorian()
 if (!eraArray)
 return;
 
-sal_Int16 e, y, m, d;
+sal_Int16 e, m, d;
+sal_Int32 y;
 
 e = fieldValue[CalendarFieldIndex::ERA];
-y = fieldValue[CalendarFieldIndex::YEAR];
+y = cast16To32(fieldValue[CalendarFieldIndex::YEAR]);
 m = fieldValue[CalendarFieldIndex::MONTH] + 1;
 d = fieldValue[CalendarFieldIndex::DAY_OF_MONTH];
 
@@ -427,7 +444,7 @@ void Calendar_gregorian::mapFromGregorian()
 
 fieldValue[CalendarFieldIndex::ERA] = e;
 fieldValue[CalendarFieldIndex::YEAR] =
-sal::static_int_cast( (e == 0) ? (eraArray[0].year - y) : 
(y - eraArray[e-1].year + 1) );
+cast32To16( (e == 0) ? (eraArray[0].year - y) : (y - 
eraArray[e-1].year + 1) );
 }
 
 #define FIELDS  ((1 << CalendarFieldIndex::ERA) | (1 << 
CalendarFieldIndex::YEAR))
@@ -436,14 +453,15 @@ void Calendar_gregorian::mapFromGregorian()
 void Calendar_gregorian::mapToGregorian()
 {
 if (eraArray && (fieldSet & FIELDS)) {
-sal_Int16 y, e = fieldValue[CalendarFieldIndex::ERA];
+sal_Int16 e = fieldValue[CalendarFieldIndex::ERA];
+sal_Int32 y;
 if (e == 0)
-y = sal::static_int_cast( eraArray[0].year - 
fieldValue[CalendarFieldIndex::YEAR] );
+y = eraArray[0].year - 
cast16To32(fieldValue[CalendarFieldIndex::YEAR]);
 else
-y = sal::static_int_cast( eraArray[e-1].year + 
fieldValue[CalendarFieldIndex::YEAR] - 1 );
+y = eraArray[e-1].year + 
cast16To32(fieldValue[CalendarFieldIndex::YEAR] - 1);
 
 fieldSetValue[CalendarFieldIndex::ERA] = y <= 0 ? 0 : 1;
-fieldSetValue[CalendarFieldIndex::YEAR] = (y <= 0 ? 1 - y : y);
+fieldSetValue[CalendarFieldIndex::YEAR] = cast32To16(y <= 0 ? 1 - y : 
y);
 fieldSet |= FIELDS;
 }
 }
@@ -664,7 +682,7 @@ Calendar_gregorian::isValid()
 // NatNum4  
NatNum9/9/11/11
 
 static sal_Int16 NatNumForCalendar(const css::lang::Locale& aLocale,
-sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, sal_Int16 
value )
+sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, sal_Int32 
value )
 {
 bool isShort = ((nCalendarDisplayCode == CalendarDisplayCode::SHORT_YEAR ||
 nCalendarDisplayCode == CalendarDisplayCode::LONG_YEAR) && value >= 
100) ||
@@ -883,7 +901,8 @@ Calendar_gregorian::getDisplayString( sal_Int32 
nCalendarDisplayCode, sal_Int16
 OUString
 Calendar_gregorian::getDisplayStringImpl( sal_Int32 nCalendarDisplayCode, 
sal_Int16 nNativeNumberMode, bool bEraMode )
 {
-sal_Int16 value = getValue(sal::static_int_cast( 
DisplayCode2FieldIndex(nCalendarDisplayCode) ));
+sal_Int32 value = cast16To32( getValue( sal::static_int_cast(
+

[Libreoffice-commits] core.git: i18npool/source svl/source

2019-04-02 Thread Takeshi Abe (via logerrit)
 i18npool/source/calendar/calendar_gregorian.cxx |2 +-
 i18npool/source/localedata/data/ja_JP.xml   |8 +++-
 svl/source/numbers/zformat.cxx  |2 +-
 3 files changed, 5 insertions(+), 7 deletions(-)

New commits:
commit 597c5d75b8e72d429e096535334eaac7973455ef
Author: Takeshi Abe 
AuthorDate: Mon Apr 1 11:44:32 2019 +0900
Commit: Eike Rathke 
CommitDate: Tue Apr 2 22:54:49 2019 +0200

Introduce next Japanese gengou era 'Reiwa'

starting from 2019-05-01, which has been announced officially.

This fills the provisional slot acknowledged at
cacbb0faef77ae8462de9ff5c7307a6a2e28b2bb.

Change-Id: Ifb12e6afaad4c66d455f664b46ec946e80324e87
Reviewed-on: https://gerrit.libreoffice.org/70028
Tested-by: Jenkins
Reviewed-by: Eike Rathke 

diff --git a/i18npool/source/calendar/calendar_gregorian.cxx 
b/i18npool/source/calendar/calendar_gregorian.cxx
index 4e4a14dc0079..662c84b897c9 100644
--- a/i18npool/source/calendar/calendar_gregorian.cxx
+++ b/i18npool/source/calendar/calendar_gregorian.cxx
@@ -209,7 +209,7 @@ static const Era gengou_eraArray[] = {
 {1912,  7, 30, 0},  // Taisho
 {1926, 12, 25, 0},  // Showa
 {1989,  1,  8, 0},  // Heisei
-{2019,  5,  1, 0},  //(Naruhito) (TODO: real era name not known yet 
(2018-07-26))
+{2019,  5,  1, 0},  // Reiwa
 {0, 0, 0, 0}
 };
 Calendar_gengou::Calendar_gengou() : Calendar_gregorian(gengou_eraArray)
diff --git a/i18npool/source/localedata/data/ja_JP.xml 
b/i18npool/source/localedata/data/ja_JP.xml
index fe4c247485f9..c15c665f2eab 100644
--- a/i18npool/source/localedata/data/ja_JP.xml
+++ b/i18npool/source/localedata/data/ja_JP.xml
@@ -481,11 +481,9 @@
   平成
 
 
-  
-  Naruhito
-  Na
-  Naruhito
+  Reiwa
+  令
+  令和
 
   
   
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index db066e136c06..daa9791dba3c 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -3476,7 +3476,7 @@ void SvNumberformat::ImpAppendEraG( OUStringBuffer& 
OutString,
 cEra = 'H';
 break;
 case 5:
-cEra = 'N'; /* TODO: the real one letter era name is not known 
yet (2018-07-26) */
+cEra = 'R';
 break;
 default:
 cEra = '?';
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: i18npool/source svl/source

2018-07-27 Thread Libreoffice Gerrit user
 i18npool/source/calendar/calendar_gregorian.cxx |9 +
 i18npool/source/localedata/data/ja_JP.xml   |7 +++
 svl/source/numbers/zformat.cxx  |3 +++
 3 files changed, 15 insertions(+), 4 deletions(-)

New commits:
commit cacbb0faef77ae8462de9ff5c7307a6a2e28b2bb
Author: Eike Rathke 
AuthorDate: Thu Jul 26 20:46:23 2018 +0200
Commit: Eike Rathke 
CommitDate: Fri Jul 27 10:50:15 2018 +0200

Prepare for "Japan's Y2K" Gengou calendar era switch after 2019-04-30

The emperor Akihito will abdicate on 2019-04-30. The next emperor
will be Naruhito, but so far neither the new era name (Heisei for
Akihito) nor its abbreviation or a Unicode character are
determined. At least introduce the new era with some dummy names
(Naruhito,Na,N).

Change-Id: I8c0af390ca0408ac259e47e7eaf2e49b5889c9ba
Reviewed-on: https://gerrit.libreoffice.org/58142
Reviewed-by: Eike Rathke 
Tested-by: Jenkins

diff --git a/i18npool/source/calendar/calendar_gregorian.cxx 
b/i18npool/source/calendar/calendar_gregorian.cxx
index a4ac0acfe53d..056d25dd2823 100644
--- a/i18npool/source/calendar/calendar_gregorian.cxx
+++ b/i18npool/source/calendar/calendar_gregorian.cxx
@@ -205,10 +205,11 @@ Calendar_hanja::loadCalendar( const OUString& 
/*uniqueID*/, const css::lang::Loc
 }
 
 static const Era gengou_eraArray[] = {
-{1868,  1,  1, 0},
-{1912,  7, 30, 0},
-{1926, 12, 25, 0},
-{1989,  1,  8, 0},
+{1868,  1,  1, 0},  // Meiji
+{1912,  7, 30, 0},  // Taisho
+{1926, 12, 25, 0},  // Showa
+{1989,  1,  8, 0},  // Heisei
+{2019,  5,  1, 0},  //(Naruhito) (TODO: real era name not known yet 
(2018-07-26))
 {0, 0, 0, 0}
 };
 Calendar_gengou::Calendar_gengou() : Calendar_gregorian(gengou_eraArray)
diff --git a/i18npool/source/localedata/data/ja_JP.xml 
b/i18npool/source/localedata/data/ja_JP.xml
index 7d7526062799..fe4c247485f9 100644
--- a/i18npool/source/localedata/data/ja_JP.xml
+++ b/i18npool/source/localedata/data/ja_JP.xml
@@ -480,6 +480,13 @@
   平
   平成
 
+
+  
+  Naruhito
+  Na
+  Naruhito
+
   
   
 sun
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 53e7a02e9acf..213e83a60a8c 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -3409,6 +3409,9 @@ void SvNumberformat::ImpAppendEraG( OUStringBuffer& 
OutString,
 case 4:
 cEra = 'H';
 break;
+case 5:
+cEra = 'N'; /* TODO: the real one letter era name is not known 
yet (2018-07-26) */
+break;
 default:
 cEra = '?';
 break;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits