Commit graph

29 commits

Author SHA1 Message Date
Linus Groh
6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Jelle Raaijmakers
9feac465dc LibCore: Convert explicit timezone to local in DateTime::parse
When we encounter an explicit timezone, we shift the time to UTC.
Because we rely on `mktime`, we need to shift it to the local time
before proceeding. If no explicit timezone is provided, local timezone
is assumed.

This fixes the "timezone-offset extension" LibJS test running on
machines with a non-UTC timezone offset.

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2022-12-19 07:07:49 -05:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
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
thankyouverycool
63d0aa9d8a LibCore: Add %l conversion specification to DateTime
Replaced by the hour as a decimal 1-12 in which single digits
are preceded by a blank
2022-11-28 13:12:08 +01:00
Timothy Flynn
a4a7efaf5f LibC+LibCore: Use tm_isdst to handle time zone offsets in DST
Previously, we were incorrectly assuming that the daylight global
variable indicated whether the current time zone is in DST. In reality,
the daylight variable only indicates whether a time zone *can* be in
DST.

Instead, the tm structure has a tm_isdst member that should be used for
this purpose. Ensure our LibC handles tm_isdst, and avoid errant usage
of the daylight variable in Core::DateTime.
2022-08-02 21:10:44 +01:00
Daniel Bertalan
32480fbeb9 LibCore: Do not refer to extern int daylight in DateTime::to_string
This variable does not exist on FreeBSD.

Co-Authored-By: Al Hoang <13622+hoanga@users.noreply.github.com>
2022-07-19 12:39:24 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02: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
Sam Atkins
4d2e18fb07 LibCore: Output invalid DateTime::to_string() specifiers as literals
While working on #13764 I noticed that DateTime::to_string() would just
return an empty String if the format included an invalid specifier
(eg `%Q`). This seems to be a mistake. POSIX date(1), which I believe
we are basing our implementation on, only replaces valid specifiers,
and any invalid ones get included as literals in the output.

For example, on Linux `date "+%Quiz"` returns "%Quiz", but we were
returning "".
2022-04-21 16:32:18 +02:00
cflip
b2ef7ee531 LibC+LibCore: Change a.m./p.m. to AM/PM 2022-04-15 08:24:20 -04:00
cflip
0500d49acb LibC+LibCore: Properly format 12-hour formatted hours
This fixes a small formatting issue where midnight and noon would
display as 00 when they should display as 12.
2022-04-15 08:24:20 -04:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Lenny Maiorani
4c5e9f5633 Everywhere: Deduplicate day/month name constants
Day and month name constants are defined in numerous places. This
pulls them together into a single place and eliminates the
duplication. It also ensures they are `constexpr`.
2022-03-18 23:48:50 +00:00
Timothy Flynn
0dfb9714fe LibCore: Use altzone for the current time zone offset during DST
Also use the daylight global to determine the current time zone name,
i.e. tzname[0] is standard time, tzname[1] is daylight savings time.

Note that altzone isn't required to be defined on all systems, so we
have to #ifdef to check if it exists in order for Lagom to build.
2022-03-13 17:50:49 +01:00
Isak Holmstrom
41765895a8 LibCore: Make FreeBSD build SerenityOS 2022-02-17 09:26:56 +00:00
Timothy Flynn
b387ac56b6 LibCore: Change DateTime format strings to be StringViews
There's no need to allocate a String for these. Note the "string"
parameter of DateTime::parse is left as a String for now; the parser is
currently using strtol which needs a NUL-terminated string. This method
can likely be rewritten with GenericLexer.
2022-01-28 20:19:05 +00:00
Timothy Flynn
29c8ec5eb6 LibCore: Support (and use) DateTime string formatting of the form %Z
This formats the time zone name. This is now used in the default format
string because DateTime is meant to represent local time; it only makes
sense to include the time zone by default now that we support non-UTC.
2022-01-25 23:21:30 +00:00
Timothy Flynn
9605be19bb LibCore: Support DateTime string formatting of the form %:z
This formats the time zone offset as "+hh:mm" or "-hh:mm". This doesn't
appear to be strictly POSIX, but it is how Linux implements this format.
2022-01-25 23:21:30 +00:00
Timothy Flynn
d9ee218701 LibCore: Support DateTime string formatting of the form %z
This formats the time zone offset as "+hhmm" or "-hhmm".
2022-01-25 23:21:30 +00:00
Idan Horowitz
95bc8e4641 LibCore: Make DateTime's members signed
Core::DateTime is essentially a C++ wrapper of the tm struct, so we
should support the same signed range as the underlying tm.
2021-08-19 19:15:00 +01:00
Brian Gianforcaro
176e1cbca7 LibCore: Remove unused header includes 2021-08-01 08:10:16 +02:00
x-yl
904322e754 LibCore: Add a way to parse a DateTime from a string
DateTime can now be parsed from a string. Implements the same formatters
as strptime: https://linux.die.net/man/3/strptime (Well, some of them at
least).
2021-06-11 23:58:28 +04:30
Andreas Kling
24c149b013 LibCore: Convert StringBuilder::appendf() => AK::Format 2021-05-07 21:12:08 +02:00
Linus Groh
dbe72fd962 Everywhere: Remove empty line after function body opening curly brace 2021-04-25 20:20:00 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
AnotherTest
db8f0a2fa6 LibCore: Remove the no-longer-used Core::DateTime::is_before() function 2021-04-18 14:18:16 +02:00
Andreas Kling
ef1e5db1d0 Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)
Good-bye LogStream. Long live AK::Format!
2021-03-12 17:29:37 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Renamed from Libraries/LibCore/DateTime.cpp (Browse further)