!439 calculate timezone by tm_gmtoff
From: @zh_xiaoyu Reviewed-by: @duguhaotian Signed-off-by: @duguhaotian
This commit is contained in:
commit
3ba9d206fe
74
0007-calculate-timezone-by-tm_gmtoff.patch
Normal file
74
0007-calculate-timezone-by-tm_gmtoff.patch
Normal file
@ -0,0 +1,74 @@
|
||||
From 15314b8d4159da27717e3e835e2cb0f90b3f7e02 Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Tue, 13 Sep 2022 20:20:58 +1400
|
||||
Subject: [PATCH] calculate timezone by tm_gmtoff
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
src/utils/cutils/utils_timestamp.c | 38 +++++++++++++++++++-----------
|
||||
1 file changed, 24 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/src/utils/cutils/utils_timestamp.c b/src/utils/cutils/utils_timestamp.c
|
||||
index 640d5dd0..c490c00e 100644
|
||||
--- a/src/utils/cutils/utils_timestamp.c
|
||||
+++ b/src/utils/cutils/utils_timestamp.c
|
||||
@@ -149,13 +149,17 @@ bool util_get_timestamp(const char *str_time, types_timestamp_t *timestamp)
|
||||
|
||||
bool get_time_buffer_help(const types_timestamp_t *timestamp, char *timebuffer, size_t maxsize, bool local_utc)
|
||||
{
|
||||
- struct tm tm_utc = { 0 };
|
||||
- struct tm tm_local = { 0 };
|
||||
- int tm_zone = 0;
|
||||
- int32_t nanos;
|
||||
int nret = 0;
|
||||
- time_t seconds;
|
||||
+ int tm_zone_hour = 0;
|
||||
+ int tm_zone_min = 0;
|
||||
+ int32_t nanos;
|
||||
+ struct tm tm_local = { 0 };
|
||||
size_t tmp_size = 0;
|
||||
+ time_t seconds;
|
||||
+ bool west_timezone = false;
|
||||
+ long int tm_gmtoff = 0;
|
||||
+ const int seconds_per_minutes = 60;
|
||||
+ const int seconds_per_hour = 3600;
|
||||
|
||||
if (timebuffer == NULL || maxsize == 0 || !timestamp->has_seconds) {
|
||||
return false;
|
||||
@@ -178,18 +182,24 @@ bool get_time_buffer_help(const types_timestamp_t *timestamp, char *timebuffer,
|
||||
goto out;
|
||||
}
|
||||
|
||||
- gmtime_r(&seconds, &tm_utc);
|
||||
- tm_zone = tm_local.tm_hour - tm_utc.tm_hour;
|
||||
- if (tm_zone < -12) {
|
||||
- tm_zone += 24;
|
||||
- } else if (tm_zone > 12) {
|
||||
- tm_zone -= 24;
|
||||
+#ifdef __USE_MISC
|
||||
+ tm_gmtoff = tm_local.tm_gmtoff;
|
||||
+#else
|
||||
+ tm_gmtoff = tm_local.__tm_gmtoff;
|
||||
+#endif
|
||||
+
|
||||
+ if (tm_gmtoff < 0) {
|
||||
+ west_timezone = true;
|
||||
+ tm_gmtoff = -tm_gmtoff;
|
||||
}
|
||||
|
||||
- if (tm_zone >= 0) {
|
||||
- nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d+%02d:00", nanos, tm_zone);
|
||||
+ tm_zone_hour = tm_gmtoff / seconds_per_hour;
|
||||
+ tm_zone_min = (tm_gmtoff - tm_zone_hour * seconds_per_hour) / seconds_per_minutes;
|
||||
+
|
||||
+ if (!west_timezone) {
|
||||
+ nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d+%02d:%02d", nanos, tm_zone_hour, tm_zone_min);
|
||||
} else {
|
||||
- nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d-%02d:00", nanos, -tm_zone);
|
||||
+ nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d-%02d:%02d", nanos, tm_zone_hour, tm_zone_min);
|
||||
}
|
||||
|
||||
out:
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
%global _version 2.0.16
|
||||
%global _release 4
|
||||
%global _release 5
|
||||
%global is_systemd 1
|
||||
%global enable_shimv2 1
|
||||
%global is_embedded 1
|
||||
@ -19,6 +19,7 @@ Patch0003: 0003-adapt-to-openssl-3.0.patch
|
||||
Patch0004: 0004-remove-redundant-header-files.patch
|
||||
Patch0005: 0005-add-isulad-args.patch
|
||||
Patch0006: 0006-invalid-free-default-runtime-and-cri-runtime-after-f.patch
|
||||
Patch0007: 0007-calculate-timezone-by-tm_gmtoff.patch
|
||||
|
||||
%ifarch x86_64 aarch64
|
||||
Provides: libhttpclient.so()(64bit)
|
||||
@ -246,6 +247,12 @@ fi
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Tue Sep 13 2022 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 2.0.16-5
|
||||
- Type: enhancement
|
||||
- ID: NA
|
||||
- SUG: NA
|
||||
- DESC: calculate timezone by tm_gmtoff
|
||||
|
||||
* Thu Sep 08 2022 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 2.0.16-4
|
||||
- Type: enhancement
|
||||
- ID: NA
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user