Blame


1 4d5ee956 2022-07-02 jrick /*
2 4d5ee956 2022-07-02 jrick * Copyright (c) 2022 Josh Rickmar <jrick@zettaport.com>
3 4d5ee956 2022-07-02 jrick *
4 4d5ee956 2022-07-02 jrick * Permission to use, copy, modify, and distribute this software for any
5 4d5ee956 2022-07-02 jrick * purpose with or without fee is hereby granted, provided that the above
6 4d5ee956 2022-07-02 jrick * copyright notice and this permission notice appear in all copies.
7 4d5ee956 2022-07-02 jrick *
8 4d5ee956 2022-07-02 jrick * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 4d5ee956 2022-07-02 jrick * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 4d5ee956 2022-07-02 jrick * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 4d5ee956 2022-07-02 jrick * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 4d5ee956 2022-07-02 jrick * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 4d5ee956 2022-07-02 jrick * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 4d5ee956 2022-07-02 jrick * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 4d5ee956 2022-07-02 jrick */
16 4d5ee956 2022-07-02 jrick
17 1b2dedff 2022-07-04 stsp #include <sys/time.h>
18 1b2dedff 2022-07-04 stsp #include <sys/types.h>
19 1b2dedff 2022-07-04 stsp
20 4d5ee956 2022-07-02 jrick #include <stdio.h>
21 4d5ee956 2022-07-02 jrick
22 4d5ee956 2022-07-02 jrick #include "got_date.h"
23 4d5ee956 2022-07-02 jrick
24 4d5ee956 2022-07-02 jrick void
25 4d5ee956 2022-07-02 jrick got_date_format_gmtoff(char *buf, size_t sz, time_t gmtoff)
26 4d5ee956 2022-07-02 jrick {
27 4d5ee956 2022-07-02 jrick long long h, m;
28 4d5ee956 2022-07-02 jrick char sign = '+';
29 4d5ee956 2022-07-02 jrick
30 4d5ee956 2022-07-02 jrick if (gmtoff < 0) {
31 4d5ee956 2022-07-02 jrick sign = '-';
32 4d5ee956 2022-07-02 jrick gmtoff = -gmtoff;
33 4d5ee956 2022-07-02 jrick }
34 4d5ee956 2022-07-02 jrick
35 4d5ee956 2022-07-02 jrick h = (long long)gmtoff / 3600;
36 4d5ee956 2022-07-02 jrick m = ((long long)gmtoff - h*3600) / 60;
37 4d5ee956 2022-07-02 jrick snprintf(buf, sz, "%c%02lld%02lld", sign, h, m);
38 4d5ee956 2022-07-02 jrick }