mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-11-04 07:10:57 +00:00 
			
		
		
		
	This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).
This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
		
	
			
		
			
				
	
	
		
			95 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			95 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
 * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
 | 
						|
 *
 | 
						|
 * SPDX-License-Identifier: BSD-2-Clause
 | 
						|
 */
 | 
						|
 | 
						|
#pragma once
 | 
						|
 | 
						|
#include <AK/Array.h>
 | 
						|
#include <AK/ByteString.h>
 | 
						|
#include <AK/Error.h>
 | 
						|
#include <AK/Format.h>
 | 
						|
#include <AK/Optional.h>
 | 
						|
#include <AK/StringView.h>
 | 
						|
#include <AK/Time.h>
 | 
						|
#include <AK/Types.h>
 | 
						|
#include <AK/Vector.h>
 | 
						|
#include <LibTimeZone/Forward.h>
 | 
						|
 | 
						|
namespace TimeZone {
 | 
						|
 | 
						|
enum class IsLink {
 | 
						|
    No,
 | 
						|
    Yes,
 | 
						|
};
 | 
						|
 | 
						|
struct TimeZoneIdentifier {
 | 
						|
    StringView name;
 | 
						|
    IsLink is_link { IsLink::No };
 | 
						|
};
 | 
						|
 | 
						|
enum class InDST {
 | 
						|
    No,
 | 
						|
    Yes,
 | 
						|
};
 | 
						|
 | 
						|
struct Offset {
 | 
						|
    i64 seconds { 0 };
 | 
						|
    InDST in_dst { InDST::No };
 | 
						|
};
 | 
						|
 | 
						|
struct NamedOffset : public Offset {
 | 
						|
    ByteString name;
 | 
						|
};
 | 
						|
 | 
						|
struct Coordinate {
 | 
						|
    constexpr float decimal_coordinate() const
 | 
						|
    {
 | 
						|
        return static_cast<float>(degrees) + (static_cast<float>(minutes) / 60.0f) + (static_cast<float>(seconds) / 3'600.0f);
 | 
						|
    }
 | 
						|
 | 
						|
    i16 degrees { 0 };
 | 
						|
    u8 minutes { 0 };
 | 
						|
    u8 seconds { 0 };
 | 
						|
};
 | 
						|
 | 
						|
struct Location {
 | 
						|
    Coordinate latitude;
 | 
						|
    Coordinate longitude;
 | 
						|
};
 | 
						|
 | 
						|
StringView system_time_zone();
 | 
						|
StringView current_time_zone();
 | 
						|
ErrorOr<void> change_time_zone(StringView time_zone);
 | 
						|
ReadonlySpan<TimeZoneIdentifier> all_time_zones();
 | 
						|
 | 
						|
Optional<TimeZone> time_zone_from_string(StringView time_zone);
 | 
						|
StringView time_zone_to_string(TimeZone time_zone);
 | 
						|
Optional<StringView> canonicalize_time_zone(StringView time_zone);
 | 
						|
 | 
						|
Optional<DaylightSavingsRule> daylight_savings_rule_from_string(StringView daylight_savings_rule);
 | 
						|
StringView daylight_savings_rule_to_string(DaylightSavingsRule daylight_savings_rule);
 | 
						|
 | 
						|
Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::UnixDateTime time);
 | 
						|
Optional<Offset> get_time_zone_offset(StringView time_zone, AK::UnixDateTime time);
 | 
						|
 | 
						|
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::UnixDateTime time);
 | 
						|
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::UnixDateTime time);
 | 
						|
 | 
						|
Optional<Location> get_time_zone_location(TimeZone time_zone);
 | 
						|
Optional<Location> get_time_zone_location(StringView time_zone);
 | 
						|
 | 
						|
Optional<Region> region_from_string(StringView region);
 | 
						|
StringView region_to_string(Region region);
 | 
						|
Vector<StringView> time_zones_in_region(StringView region);
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
template<>
 | 
						|
struct AK::Formatter<TimeZone::TimeZone> : Formatter<FormatString> {
 | 
						|
    ErrorOr<void> format(FormatBuilder& builder, TimeZone::TimeZone const& time_zone)
 | 
						|
    {
 | 
						|
        return Formatter<FormatString>::format(builder, TimeZone::time_zone_to_string(time_zone));
 | 
						|
    }
 | 
						|
};
 |