Blame


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