Commit Graph

27 Commits

Author SHA1 Message Date
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Linus Groh
a6ba82fc49 LibTimeZone: Resolve /etc/localtime with realpath(), not readlink()
On Fedora Silverblue and other OSTree-based systems, /etc/localtime is
a symlink to /run/host/etc/localtime, which then points to the expected
zoneinfo file, e.g. ../usr/share/zoneinfo/Europe/Berlin.
By using realpath() instead of readlink() we can resolve the symlink
recursively and avoid falling back to UTC.
2022-10-17 22:19:50 +02:00
Timothy Flynn
ed612d835d LibTimeZone: Default to UTC if parsing the TZ environment variable fails
Commit c3fd455 changed LibTimeZone to fall back to the system time zone
when we fail to parse the TZ environment variable. This behavior differs
from both our LibC and glibc; they abort parsing and default to UTC.

This changes LibTimeZone to behave the same way to avoid a very awkward
situation where some parts of the codebase thinks the timezone is UTC,
and others think the timezone is whatever /etc/timezone indicates.
2022-10-17 21:50:55 +02:00
Andrew Kaster
b8e51425e9 Lagom+CMake: Propagate dependencies for generated custom targets
We have logic for serenity_generated_sources which works well for source
files that are specified in GENERATED_SOURCES prior to calling
serenity_lib or serenity_bin. However, code generated with
invoke_generator, and the LibWeb generators do not always follow the
pattern of the IDL and GML files.

For the LibWeb generators, we can just add_dependencies to LibWeb at the
time we declare the generate_Foo custom target. However for LibLocale,
LibTimeZone, and LibUnicode, we don't have the name of the target
available, so export the name in a variable to set into
GENERATED_SOURCES.

To make this work for Lagom, we need to make sure that lagom_lib and
serenity_bin in Lagom/CMakeLists.txt call serenity_generated_sources on
the target.

This enables the Xcode generator on macOS hosts, at least for Lagom.
2022-10-17 15:55:55 +02:00
Andrew Kaster
828441852f Everywhere: Replace uses of __serenity__ with AK_OS_SERENITY
Now that we have OS macros for essentially every supported OS, let's try
to use them everywhere.
2022-10-10 12:23:12 +02:00
Timothy Flynn
c3fd4554a6 LibTimeZone: Do not use tzname to determine the current time zone
The tzname array stores the abbreviated names of the current time zone
when in standard and daylight time. These abbreviations are ambiguous;
a single abbreviation often maps to multiple time zones. For example,
EST is used by America/New_York and America/Detroit, and CST could be
the abbreviation of Central Standard Time or China Standard Time.

Instead, we mimic a subset of how both ICU and Howard Hinnant's "date"
library determines the current time zone. First, we try to parse the TZ
environment variable. If that fails, or isn't set, we try to resolve the
/etc/localtime symbolic link. On most Linux systems and on macOS, this
is a link to the current TZDB file in use.

If all of the above fails, we fall back to UTC.
2022-09-28 23:52:51 +01:00
sin-ack
c70f45ff44 Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the
StringView users. This is an important step towards the goal of removing
StringView(char const*), as it moves the responsibility of calculating
the size of the string to the user of the StringView (which will prevent
naive uses causing OOB access).
2022-07-12 23:11:35 +02:00
Timothy Flynn
fa005bd276 LibTimeZone: Parse and generate a list of time zones used by region
The zone1970.tab file in the TZDB contains regional time zone data, some
of which we already parse for the system time zone settings map.

This parses the region names from that file and generates a list of time
zones which are used in each of those regions.
2022-07-06 16:56:42 +02:00
Andrew Kaster
5120b39d0e Meta+Userland: Add ENABLE_USERSPACE_COVERAGE_COLLECTION CMake option
This option sets -fprofile-instr-generate -fcoverage-mapping for Clang
builds only on almost all of Userland. Loader and LibTimeZone are
exempt. This can be used for generating code coverage reports, or even
PGO in the future.
2022-05-02 01:46:18 +02:00
Timothy Flynn
ea814a3ce6 LibTimeZone: Parse and generate time zone coordinate data 2022-02-03 16:11:15 +01:00
Timothy Flynn
6efbafa6e0 Everywhere: Update copyrights with my new serenityos.org e-mail :^) 2022-01-31 18:23:22 +00:00
Timothy Flynn
a027ccad75 LibTimeZone+Userland: Rename current_time_zone to system_time_zone
This renames the current implementation of current_time_zone to
system_time_zone to more clearly indicate what it is. Then reimplements
current_time_zone to return whatever was set up by tzset, falling back
to UTC if something went awry, for convenience.
2022-01-25 18:39:36 +00:00
Timothy Flynn
7103012c7d LibTimeZone: Add an API to retrieve both daylight and standard offsets
This API will also include the formatted name of the time zone, with
respect for DST (e.g. EST vs EDT for America/New_York).
2022-01-25 18:39:36 +00:00
Timothy Flynn
7f1404b870 LibTimeZone: Use /etc/timezone as the basis for the system time zone
This changes LibTimeZone to read the current time zone from the file
/etc/timezone rather than using tzset/tzname. Instead, in a subsequent
commit, LibC's time methods will be changed to used LibTimeZone to
retrieve the system time zone.

Also add an API to set the system time zone. This method is only allowed
when running within Serenity.
2022-01-23 12:48:26 +00:00
Timothy Flynn
da27937144 LibTimeZone: Add an API to retrieve a list of all known IANA time zones 2022-01-23 12:48:26 +00:00
Timothy Flynn
6988403d59 DynamicLoader+LibC+LibTimeZone: Include LibTimeZone sources in LibC
LibTimeZone will be needed directly within LibC for functions such as
localtime(). This change adds LibTimeZone directly within LibC, so that
LibTimeZone isn't its own .so library anymore.

LibTimeZone itself is compiled as an object library to make it easier to
give it generator-specific compilation flags.
2022-01-23 12:48:26 +00:00
Timothy Flynn
70f49d0696 LibJS+LibTimeZone+LibUnicode: Indicate whether a time zone is in DST
Return whether the time zone is in DST during the provided time from
TimeZone::get_time_zone_offset,
2022-01-19 21:20:41 +00:00
Timothy Flynn
0e58b04b5c LibTimeZone: Begin parsing and generating DaylightSavings rules 2022-01-19 21:20:41 +00:00
Timothy Flynn
247caac7a8 LibTimeZone: Canonicalize the current time zone and fall back to UTC
If the tzname is unknown, fall back to UTC for now. Unknown time zones
are most likely due to not parsing RULE entries yet, but at the very
least, it only makes sense for current_time_zone to return a time zone
that LibTimeZone actually knows about.
2022-01-15 20:13:48 +01:00
Timothy Flynn
8a4ac9c387 LibTimeZone: Add an API to retrieve the system's current time zone
This is a wrapper API around the POSIX tzset / tzname information. It
is to help ensure that tzset is invoked before accessing tzname.
2022-01-12 15:43:12 +01:00
Linus Groh
205d63c3f0 LibTimeZone: Operate in UTC-only mode when !ENABLE_TIME_ZONE_DATA
Instead of only having dummy functions that don't work with any input,
let's at least support one time zone: 'UTC'. This matches the basic
Temporal implementation for engines without ECMA-262, for example.
2022-01-11 22:17:39 +01:00
Timothy Flynn
09c0324880 LibTimeZone: Begin generating GMT offset rules for each time zone
This is a rather naive implementation, but serves as a first pass at
determining the GMT offset for a time zone at a particular point in
time. This implementation ignores DST (because we are not parsing any
RULE entries yet), and ignores any offset patterns of the form "Mon>4"
or "lastSun".
2022-01-11 00:36:45 +01:00
Timothy Flynn
e9c42d0bc5 LibTimeZone: Add methods to canonicalize a time zone name 2022-01-11 00:36:45 +01:00
Timothy Flynn
1c2c98ac5d LibTimeZone: Add method to convert a time zone to a string 2022-01-11 00:36:45 +01:00
Timothy Flynn
d627367489 LibTimeZone: Do not separate the generated data from the main library
This CMakeLists.txt was basically copy-pasted from LibUnicode, where the
generated data is separated into its own library. This was to let other
libraries / applications decide if they actually want to link the data
because it is so large. LibTimeZone's generated data is significantly
smaller, so this separation really isn't needed.
2022-01-11 00:36:45 +01:00
Timothy Flynn
9253e695d1 LibTimeZone: Parse ZONE entries from the TZDB and generate their names 2022-01-08 12:45:34 +01:00
Timothy Flynn
8669b25cea LibTimeZone+Meta: Add plumbing for an IANA Time Zone Database generator
The IANA Time Zone Database contains data needed, at least, for various
JavaScript objects. This adds plumbing for a parser and code generator
for this data. The generated data will be made available by LibTimeZone,
much like how UCD and CLDR data is available through LibUnicode.
2022-01-08 12:45:34 +01:00