Annotation of src/usr.bin/rcs/rcstime.c, Revision 1.1
1.1 ! joris 1: /* $OpenBSD: rcstime.c,v 1.5 2006/04/17 06:33:22 ray Exp $ */
! 2: /*
! 3: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
! 4: * All rights reserved.
! 5: *
! 6: * Redistribution and use in source and binary forms, with or without
! 7: * modification, are permitted provided that the following conditions
! 8: * are met:
! 9: *
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. The name of the author may not be used to endorse or promote products
! 13: * derived from this software without specific prior written permission.
! 14: *
! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
! 16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
! 17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
! 18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! 19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! 20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
! 21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
! 22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
! 23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 25: */
! 26:
! 27: #include "includes.h"
! 28:
! 29: #include "rcs.h"
! 30:
! 31: void
! 32: rcs_set_tz(char *tz, struct rcs_delta *rdp, struct tm *tb)
! 33: {
! 34: int tzone;
! 35: int pos;
! 36: char *h, *m;
! 37: struct tm *ltb;
! 38: time_t now;
! 39:
! 40: if (!strcmp(tz, "LT")) {
! 41: now = mktime(&rdp->rd_date);
! 42: ltb = localtime(&now);
! 43: ltb->tm_hour += ((int)ltb->tm_gmtoff/3600);
! 44: memcpy(tb, ltb, sizeof(struct tm));
! 45: } else {
! 46: pos = 0;
! 47: switch (*tz) {
! 48: case '-':
! 49: break;
! 50: case '+':
! 51: pos = 1;
! 52: break;
! 53: default:
! 54: errx(1, "%s: not a known time zone", tz);
! 55: }
! 56:
! 57: h = (tz + 1);
! 58: if ((m = strrchr(tz, ':')) != NULL)
! 59: *(m++) = '\0';
! 60:
! 61: memcpy(tb, &rdp->rd_date, sizeof(struct tm));
! 62:
! 63: tzone = atoi(h);
! 64: if ((tzone >= 24) && (tzone <= -24))
! 65: errx(1, "%s: not a known time zone", tz);
! 66:
! 67: if (pos) {
! 68: tb->tm_hour += tzone;
! 69: tb->tm_gmtoff += (tzone * 3600);
! 70: } else {
! 71: tb->tm_hour -= tzone;
! 72: tb->tm_gmtoff -= (tzone * 3600);
! 73: }
! 74:
! 75: if ((tb->tm_hour >= 24) || (tb->tm_hour <= -24))
! 76: tb->tm_hour = 0;
! 77:
! 78: if (m != NULL) {
! 79: tzone = atoi(m);
! 80: if (tzone >= 60)
! 81: errx(1, "%s: not a known time zone", tz);
! 82:
! 83: if ((tb->tm_min + tzone) >= 60) {
! 84: tb->tm_hour++;
! 85: tb->tm_min -= (60 - tzone);
! 86: } else
! 87: tb->tm_min += tzone;
! 88:
! 89: tb->tm_gmtoff += (tzone*60);
! 90: }
! 91: }
! 92: }