79 lines
2.8 KiB
C
79 lines
2.8 KiB
C
/* _,.---._ .-._ .--.-. ,--.--------.
|
|
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
|
|
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
|
|
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
|
|
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
|
|
* |==|,| | -|==| , '=' |==| - _ | |==|- |
|
|
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
|
|
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
|
|
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
|
|
* _ __ ,---. .-._ .=-.-. _,.----.
|
|
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
|
|
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
|
|
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
|
|
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
|
|
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
|
|
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
|
|
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
|
|
* `--`---' `--` `--`./ `--``--`-`
|
|
*
|
|
* @(#)Copyright (c) 2024, Nathan D. Fisher.
|
|
*
|
|
* This is free software. It comes with NO WARRANTY.
|
|
* Permission to use, modify and distribute this source code
|
|
* is granted subject to the following conditions.
|
|
* 1/ that the above copyright notice and this notice
|
|
* are preserved in all copies and that due credit be given
|
|
* to the author.
|
|
* 2/ that any changes to this code are clearly commented
|
|
* as such so that the author does not get blamed for bugs
|
|
* other than his own.
|
|
*/
|
|
|
|
#include "epoch.h"
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
int offsetNew(TzOffset *offs, offsetSign sign, uint8_t hours, uint8_t minutes) {
|
|
if (offs == NULL) return 1;
|
|
if (hours > 12) return 2;
|
|
if (hours > 11 && minutes > 0) return 3;
|
|
if (minutes > 59) return 4;
|
|
offs->sign = sign;
|
|
offs->hours = hours;
|
|
offs->minutes = minutes;
|
|
return 0;
|
|
}
|
|
|
|
void printTz(TimeZone *zone) {
|
|
switch (zone->tag) {
|
|
case UTC: printf("UTC");
|
|
case Offset:
|
|
switch (zone->offset->sign) {
|
|
case Positive:
|
|
puts("+");
|
|
break;
|
|
case Negative:
|
|
puts("-");
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
printf("%.2u:%.2u", zone->offset->hours, zone->offset->minutes);
|
|
}
|
|
}
|
|
|
|
int64_t timezoneAsSeconds(TimeZone *tz) {
|
|
int64_t base;
|
|
|
|
switch (tz->tag) {
|
|
case Offset:
|
|
base = (int64_t)tz->offset->hours * SECONDS_PER_HOUR + (int64_t)tz->offset->minutes * 60;
|
|
switch (tz->offset->sign) {
|
|
case Negative: return -base;
|
|
default: return base;
|
|
}
|
|
default: return 0;
|
|
}
|
|
}
|