mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Merge branch 'wip/pwithnall/3119-Ey-years' into 'main'
gdatetime: Disable ERA support on platforms which don’t support this See merge request GNOME/glib!3734
This commit is contained in:
commit
93eeed4023
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 Philip Withnall
|
||||
* Copyright 2023 GNOME Foundation Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*
|
||||
@ -15,6 +15,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* - Philip Withnall <pwithnall@gnome.org>
|
||||
*/
|
||||
|
||||
#include "glib.h"
|
||||
@ -137,7 +140,7 @@ _g_era_description_segment_unref (GEraDescriptionSegment *segment)
|
||||
*
|
||||
* Parse an ERA description string. See [`nl_langinfo(3)`](man:nl_langinfo(3)).
|
||||
*
|
||||
* Example description string for th_TR.UTF-8:
|
||||
* Example description string for th_TH.UTF-8:
|
||||
* ```
|
||||
* +:1:-543/01/01:+*:พ.ศ.:%EC %Ey
|
||||
* ```
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 Philip Withnall
|
||||
* Copyright 2023 GNOME Foundation Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*
|
||||
@ -15,6 +15,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* - Philip Withnall <pwithnall@gnome.org>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
@ -5,6 +5,7 @@
|
||||
* Copyright (C) 2010 Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
* Copyright © 2010 Codethink Limited
|
||||
* Copyright © 2018 Tomasz Miąsko
|
||||
* Copyright 2023 GNOME Foundation Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*
|
||||
@ -26,6 +27,7 @@
|
||||
* Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
* Ryan Lortie <desrt@desrt.ca>
|
||||
* Robert Ancell <robert.ancell@canonical.com>
|
||||
* Philip Withnall <pwithnall@gnome.org>
|
||||
*/
|
||||
|
||||
/* Algorithms within this file are based on the Calendar FAQ by
|
||||
@ -163,11 +165,8 @@ static const guint16 days_in_year[2][13] =
|
||||
#define GET_AMPM_IS_LOCALE TRUE
|
||||
|
||||
#define PREFERRED_DATE_TIME_FMT nl_langinfo (D_T_FMT)
|
||||
#define PREFERRED_ERA_DATE_TIME_FMT nl_langinfo (ERA_D_T_FMT)
|
||||
#define PREFERRED_DATE_FMT nl_langinfo (D_FMT)
|
||||
#define PREFERRED_ERA_DATE_FMT nl_langinfo (ERA_D_FMT)
|
||||
#define PREFERRED_TIME_FMT nl_langinfo (T_FMT)
|
||||
#define PREFERRED_ERA_TIME_FMT nl_langinfo (ERA_T_FMT)
|
||||
#define PREFERRED_12HR_TIME_FMT nl_langinfo (T_FMT_AMPM)
|
||||
|
||||
static const gint weekday_item[2][7] =
|
||||
@ -191,10 +190,6 @@ static const gint month_item[2][12] =
|
||||
#define MONTH_FULL(d) nl_langinfo (month_item[1][g_date_time_get_month (d) - 1])
|
||||
#define MONTH_FULL_IS_LOCALE TRUE
|
||||
|
||||
#define ERA_DESCRIPTION nl_langinfo (ERA)
|
||||
#define ERA_DESCRIPTION_IS_LOCALE TRUE
|
||||
#define ERA_DESCRIPTION_N_SEGMENTS (int) (gintptr) nl_langinfo (_NL_TIME_ERA_NUM_ENTRIES)
|
||||
|
||||
#else
|
||||
|
||||
#define GET_AMPM(d) (get_fallback_ampm (g_date_time_get_hour (d)))
|
||||
@ -202,15 +197,12 @@ static const gint month_item[2][12] =
|
||||
|
||||
/* Translators: this is the preferred format for expressing the date and the time */
|
||||
#define PREFERRED_DATE_TIME_FMT C_("GDateTime", "%a %b %e %H:%M:%S %Y")
|
||||
#define PREFERRED_ERA_DATE_TIME_FMT PREFERRED_DATE_TIME_FMT
|
||||
|
||||
/* Translators: this is the preferred format for expressing the date */
|
||||
#define PREFERRED_DATE_FMT C_("GDateTime", "%m/%d/%y")
|
||||
#define PREFERRED_ERA_DATE_FMT PREFERRED_DATE_FMT
|
||||
|
||||
/* Translators: this is the preferred format for expressing the time */
|
||||
#define PREFERRED_TIME_FMT C_("GDateTime", "%H:%M:%S")
|
||||
#define PREFERRED_ERA_TIME_FMT PREFERRED_TIME_FMT
|
||||
|
||||
/* Translators: this is the preferred format for expressing 12 hour time */
|
||||
#define PREFERRED_12HR_TIME_FMT C_("GDateTime", "%I:%M:%S %p")
|
||||
@ -230,10 +222,6 @@ static const gint month_item[2][12] =
|
||||
#define MONTH_FULL(d) (get_month_name_standalone (g_date_time_get_month (d)))
|
||||
#define MONTH_FULL_IS_LOCALE FALSE
|
||||
|
||||
#define ERA_DESCRIPTION NULL
|
||||
#define ERA_DESCRIPTION_IS_LOCALE FALSE
|
||||
#define ERA_DESCRIPTION_N_SEGMENTS 0
|
||||
|
||||
static const gchar *
|
||||
get_month_name_standalone (gint month)
|
||||
{
|
||||
@ -570,6 +558,28 @@ get_month_name_abbr_with_day (gint month)
|
||||
|
||||
#endif /* HAVE_LANGINFO_ABALTMON */
|
||||
|
||||
#ifdef HAVE_LANGINFO_ERA
|
||||
|
||||
#define PREFERRED_ERA_DATE_TIME_FMT nl_langinfo (ERA_D_T_FMT)
|
||||
#define PREFERRED_ERA_DATE_FMT nl_langinfo (ERA_D_FMT)
|
||||
#define PREFERRED_ERA_TIME_FMT nl_langinfo (ERA_T_FMT)
|
||||
|
||||
#define ERA_DESCRIPTION nl_langinfo (ERA)
|
||||
#define ERA_DESCRIPTION_IS_LOCALE TRUE
|
||||
#define ERA_DESCRIPTION_N_SEGMENTS (int) (gintptr) nl_langinfo (_NL_TIME_ERA_NUM_ENTRIES)
|
||||
|
||||
#else /* if !HAVE_LANGINFO_ERA */
|
||||
|
||||
#define PREFERRED_ERA_DATE_TIME_FMT PREFERRED_DATE_TIME_FMT
|
||||
#define PREFERRED_ERA_DATE_FMT PREFERRED_DATE_FMT
|
||||
#define PREFERRED_ERA_TIME_FMT PREFERRED_TIME_FMT
|
||||
|
||||
#define ERA_DESCRIPTION NULL
|
||||
#define ERA_DESCRIPTION_IS_LOCALE FALSE
|
||||
#define ERA_DESCRIPTION_N_SEGMENTS 0
|
||||
|
||||
#endif /* !HAVE_LANGINFO_ERA */
|
||||
|
||||
/* Format AM/PM indicator if the locale does not have a localized version. */
|
||||
static const gchar *
|
||||
get_fallback_ampm (gint hour)
|
||||
@ -2960,10 +2970,13 @@ date_time_lookup_era (GDateTime *datetime,
|
||||
|
||||
if (era_description_str != NULL)
|
||||
static_era_description = _g_era_description_parse (era_description_str);
|
||||
if (static_era_description == NULL)
|
||||
g_warning ("Could not parse ERA description: %s", era_description_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_clear_pointer (&static_era_description, g_ptr_array_unref);
|
||||
}
|
||||
|
||||
if (static_era_description == NULL)
|
||||
g_warning ("Could not parse ERA description: %s", era_description_str);
|
||||
|
||||
g_free (tmp);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* gdatetime-tests.c
|
||||
*
|
||||
* Copyright (C) 2009-2010 Christian Hergert <chris@dronelabs.com>
|
||||
* Copyright 2023 Philip Withnall
|
||||
* Copyright 2023 GNOME Foundation Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*
|
||||
@ -17,6 +17,10 @@
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* - Christian Hergert <chris@dronelabs.com>
|
||||
* - Philip Withnall <pwithnall@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@ -1721,12 +1725,21 @@ test_non_utf8_printf (void)
|
||||
TEST_PRINTF ("%%", "%");
|
||||
TEST_PRINTF ("%", "");
|
||||
TEST_PRINTF ("%9", NULL);
|
||||
#ifdef HAVE_LANGINFO_ERA
|
||||
TEST_PRINTF ("%Ec", "平成21年10月24日 00時00分00秒");
|
||||
TEST_PRINTF ("%EC", "平成");
|
||||
TEST_PRINTF ("%Ex", "平成21年10月24日");
|
||||
TEST_PRINTF ("%EX", "00時00分00秒");
|
||||
TEST_PRINTF ("%Ey", "21");
|
||||
TEST_PRINTF ("%EY", "平成21年");
|
||||
#else
|
||||
TEST_PRINTF ("%Ec", "平成21年10月24日 00時00分00秒");
|
||||
TEST_PRINTF ("%EC", "平成");
|
||||
TEST_PRINTF ("%Ex", "2009\345\271\26410\346\234\21024\346\227\245");
|
||||
TEST_PRINTF ("%EX", "00\346\231\20200\345\210\20600\347\247\222");
|
||||
TEST_PRINTF ("%Ey", "09");
|
||||
TEST_PRINTF ("%EY", "2009");
|
||||
#endif
|
||||
|
||||
setlocale (LC_ALL, oldlocale);
|
||||
g_free (oldlocale);
|
||||
@ -1885,14 +1898,25 @@ test_modifiers (void)
|
||||
setlocale (LC_ALL, "en_GB.utf-8");
|
||||
if (strstr (setlocale (LC_ALL, NULL), "en_GB") != NULL)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
TEST_PRINTF_DATE (2009, 1, 1, "%c", "thu 01 jan 2009 00:00:00 utc");
|
||||
TEST_PRINTF_DATE (2009, 1, 1, "%Ec", "thu 01 jan 2009 00:00:00 utc");
|
||||
#else
|
||||
/* macOS uses a figure space (U+2007) to pad the day */
|
||||
TEST_PRINTF_DATE (2009, 1, 1, "%c", "thu " "\xe2\x80\x87" "1 jan 00:00:00 2009");
|
||||
TEST_PRINTF_DATE (2009, 1, 1, "%Ec", "thu " "\xe2\x80\x87" "1 jan 00:00:00 2009");
|
||||
#endif
|
||||
|
||||
TEST_PRINTF_DATE (2009, 1, 1, "%C", "20");
|
||||
TEST_PRINTF_DATE (2009, 1, 1, "%EC", "20");
|
||||
|
||||
#ifndef __APPLE__
|
||||
TEST_PRINTF_DATE (2009, 1, 2, "%x", "02/01/09");
|
||||
TEST_PRINTF_DATE (2009, 1, 2, "%Ex", "02/01/09");
|
||||
#else
|
||||
TEST_PRINTF_DATE (2009, 1, 2, "%x", "02/01/2009");
|
||||
TEST_PRINTF_DATE (2009, 1, 2, "%Ex", "02/01/2009");
|
||||
#endif
|
||||
|
||||
TEST_PRINTF_TIME (1, 2, 3, "%X", "01:02:03");
|
||||
TEST_PRINTF_TIME (1, 2, 3, "%EX", "01:02:03");
|
||||
@ -2248,6 +2272,7 @@ test_all_dates (void)
|
||||
static void
|
||||
test_date_time_eras_japan (void)
|
||||
{
|
||||
#ifdef HAVE_LANGINFO_ERA
|
||||
gchar *oldlocale;
|
||||
|
||||
oldlocale = g_strdup (setlocale (LC_ALL, NULL));
|
||||
@ -2286,11 +2311,15 @@ test_date_time_eras_japan (void)
|
||||
|
||||
setlocale (LC_ALL, oldlocale);
|
||||
g_free (oldlocale);
|
||||
#else
|
||||
g_test_skip ("nl_langinfo(ERA) not supported, skipping era tests");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
test_date_time_eras_thailand (void)
|
||||
{
|
||||
#ifdef HAVE_LANGINFO_ERA
|
||||
gchar *oldlocale;
|
||||
|
||||
oldlocale = g_strdup (setlocale (LC_ALL, NULL));
|
||||
@ -2314,6 +2343,9 @@ test_date_time_eras_thailand (void)
|
||||
|
||||
setlocale (LC_ALL, oldlocale);
|
||||
g_free (oldlocale);
|
||||
#else
|
||||
g_test_skip ("nl_langinfo(ERA) not supported, skipping era tests");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
31
meson.build
31
meson.build
@ -1299,6 +1299,7 @@ if cc.links('''#include <langinfo.h>
|
||||
endif
|
||||
|
||||
# Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
|
||||
have_langinfo_time = false
|
||||
if cc.links('''#include <langinfo.h>
|
||||
int main (int argc, char ** argv) {
|
||||
char *str;
|
||||
@ -1311,15 +1312,29 @@ if cc.links('''#include <langinfo.h>
|
||||
str = nl_langinfo (ABMON_12);
|
||||
str = nl_langinfo (DAY_1);
|
||||
str = nl_langinfo (ABDAY_7);
|
||||
return 0;
|
||||
}''', name : 'nl_langinfo (PM_STR)')
|
||||
have_langinfo_time = true
|
||||
glib_conf.set('HAVE_LANGINFO_TIME', 1)
|
||||
endif
|
||||
|
||||
# Linux glibc supports ERA, but FreeBSD and macOS don’t
|
||||
if cc.links('''#include <langinfo.h>
|
||||
int main (int argc, char **argv) {
|
||||
char *str;
|
||||
str = nl_langinfo (ERA);
|
||||
str = nl_langinfo (ERA_D_T_FMT);
|
||||
str = nl_langinfo (ERA_D_FMT);
|
||||
str = nl_langinfo (ERA_T_FMT);
|
||||
str = nl_langinfo (_NL_TIME_ERA_NUM_ENTRIES);
|
||||
return 0;
|
||||
}''', name : 'nl_langinfo (PM_STR)')
|
||||
glib_conf.set('HAVE_LANGINFO_TIME', 1)
|
||||
}''', name : 'nl_langinfo (ERA)')
|
||||
glib_conf.set('HAVE_LANGINFO_ERA', 1)
|
||||
if not have_langinfo_time
|
||||
error('nl_langinfo(ERA) is supported but more basic nl_langinfo() functionality like PM_STR is not')
|
||||
endif
|
||||
endif
|
||||
|
||||
if cc.links('''#include <langinfo.h>
|
||||
int main (int argc, char ** argv) {
|
||||
char *str;
|
||||
@ -1336,6 +1351,9 @@ if cc.links('''#include <langinfo.h>
|
||||
return 0;
|
||||
}''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
|
||||
glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
|
||||
if not have_langinfo_time
|
||||
error('nl_langinfo(_NL_CTYPE_OUTDIGITn_MB) is supported but more basic nl_langinfo() functionality like PM_STR is not')
|
||||
endif
|
||||
endif
|
||||
|
||||
# Check for nl_langinfo and alternative month names
|
||||
@ -1360,6 +1378,9 @@ if cc.links('''#ifndef _GNU_SOURCE
|
||||
return 0;
|
||||
}''', name : 'nl_langinfo (ALTMON_n)')
|
||||
glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
|
||||
if not have_langinfo_time
|
||||
error('nl_langinfo(ALTMON_n) is supported but more basic nl_langinfo() functionality like PM_STR is not')
|
||||
endif
|
||||
endif
|
||||
|
||||
# Check for nl_langinfo and abbreviated alternative month names
|
||||
@ -1384,6 +1405,9 @@ if cc.links('''#ifndef _GNU_SOURCE
|
||||
return 0;
|
||||
}''', name : 'nl_langinfo (_NL_ABALTMON_n)')
|
||||
glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
|
||||
if not have_langinfo_time
|
||||
error('nl_langinfo(_NL_ABALTMON_n) is supported but more basic nl_langinfo() functionality like PM_STR is not')
|
||||
endif
|
||||
endif
|
||||
|
||||
# Check for nl_langinfo and _NL_TIME_CODESET
|
||||
@ -1393,6 +1417,9 @@ if cc.links('''#include <langinfo.h>
|
||||
return 0;
|
||||
}''', name : 'nl_langinfo and _NL_TIME_CODESET')
|
||||
glib_conf.set('HAVE_LANGINFO_TIME_CODESET', 1)
|
||||
if not have_langinfo_time
|
||||
error('nl_langinfo(_NL_TIME_CODESET) is supported but more basic nl_langinfo() functionality like PM_STR is not')
|
||||
endif
|
||||
endif
|
||||
|
||||
# Check if C compiler supports the 'signed' keyword
|
||||
|
Loading…
Reference in New Issue
Block a user