[BACK]Return to rcstime.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/rcstime.c, Revision 1.5

1.5     ! ray         1: /*     $OpenBSD: rcstime.c,v 1.4 2006/04/14 02:49:44 deraadt Exp $     */
1.1       xsa         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 "log.h"
                     30: #include "rcs.h"
                     31:
1.3       joris      32: void
                     33: rcs_set_tz(char *tz, struct rcs_delta *rdp, struct tm *tb)
1.1       xsa        34: {
                     35:        int tzone;
1.5     ! ray        36:        int pos;
1.1       xsa        37:        char *h, *m;
1.3       joris      38:        struct tm *ltb;
1.1       xsa        39:        time_t now;
                     40:
                     41:        if (!strcmp(tz, "LT")) {
                     42:                now = mktime(&rdp->rd_date);
1.3       joris      43:                ltb = localtime(&now);
                     44:                ltb->tm_hour += ((int)ltb->tm_gmtoff/3600);
                     45:                memcpy(tb, ltb, sizeof(struct tm));
1.1       xsa        46:        } else {
1.5     ! ray        47:                pos = 0;
1.1       xsa        48:                switch (*tz) {
                     49:                case '-':
1.3       joris      50:                        break;
1.4       deraadt    51:                case '+':
1.3       joris      52:                        pos = 1;
1.1       xsa        53:                        break;
                     54:                default:
                     55:                        fatal("%s: not a known time zone", tz);
                     56:                }
                     57:
1.3       joris      58:                h = (tz + 1);
1.1       xsa        59:                if ((m = strrchr(tz, ':')) != NULL)
                     60:                        *(m++) = '\0';
                     61:
1.3       joris      62:                memcpy(tb, &rdp->rd_date, sizeof(struct tm));
1.1       xsa        63:
                     64:                tzone = atoi(h);
                     65:                if ((tzone >= 24) && (tzone <= -24))
                     66:                        fatal("%s: not a known time zone", tz);
                     67:
1.3       joris      68:                if (pos) {
                     69:                        tb->tm_hour += tzone;
                     70:                        tb->tm_gmtoff += (tzone * 3600);
                     71:                } else {
                     72:                        tb->tm_hour -= tzone;
                     73:                        tb->tm_gmtoff -= (tzone * 3600);
                     74:                }
                     75:
                     76:                if ((tb->tm_hour >= 24) || (tb->tm_hour <= -24))
1.1       xsa        77:                        tb->tm_hour = 0;
                     78:
                     79:                if (m != NULL) {
                     80:                        tzone = atoi(m);
                     81:                        if (tzone >= 60)
                     82:                                fatal("%s: not a known time zone", tz);
                     83:
                     84:                        if ((tb->tm_min + tzone) >= 60) {
                     85:                                tb->tm_hour++;
1.3       joris      86:                                tb->tm_min -= (60 - tzone);
1.1       xsa        87:                        } else
                     88:                                tb->tm_min += tzone;
                     89:
                     90:                        tb->tm_gmtoff += (tzone*60);
                     91:                }
                     92:        }
                     93: }