[libc-commits] [libc] [libc] implement localtime (PR #110363)
Зишан Мирза via libc-commits
libc-commits at lists.llvm.org
Tue Oct 8 06:53:31 PDT 2024
================
@@ -0,0 +1,60 @@
+//===-- Implementation of timezone functions ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/time/timezone.h"
+#include "src/__support/CPP/limits.h" // INT_MIN, INT_MAX
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/time/time_utils.h"
+
+#define BUF_SIZE 1024
+
+namespace LIBC_NAMESPACE_DECL {
+namespace timezone {
+
+using LIBC_NAMESPACE::time_utils::TimeConstants;
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int get_timezone_offset(char *timezone) {
+ int offset = 0;
+ LIBC_NAMESPACE::cpp::string_view tz(timezone);
+
+ if (tz.starts_with("America")) {
+ if (tz.ends_with("San_Francisco")) {
+ offset = -8;
+ }
+
+ if (tz.ends_with("Chicago")) {
+ offset = -4;
+ }
----------------
zimirza wrote:
I think it is better to rewrite timezones. Manually defining timezones is really not really good. I think it should be possible to get the offset from `/etc/timezone` as an integer.
https://github.com/llvm/llvm-project/pull/110363
More information about the libc-commits
mailing list