/* $NetBSD: rcstime.c,v 1.2 2016/01/14 04:22:39 christos Exp $ */ /* Convert between RCS time format and Posix and/or C formats. */ /* Copyright 1992, 1993, 1994, 1995 Paul Eggert Distributed under license by the Free Software Foundation, Inc. This file is part of RCS. RCS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. RCS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with RCS; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Report problems and direct all questions to: rcs-bugs@cs.purdue.edu */ #include "rcsbase.h" #include "partime.h" #include "maketime.h" libId(rcstimeId, "Id: rcstime.c,v 1.4 1995/06/16 06:19:24 eggert Exp ") static long zone_offset; /* seconds east of UTC, or TM_LOCAL_ZONE */ static int use_zone_offset; /* if zero, use UTC without zone indication */ /* * Convert Unix time to RCS format. * For compatibility with older versions of RCS, * dates from 1900 through 1999 are stored without the leading "19". */ void time2date(unixtime,date) time_t unixtime; char date[datesize]; { register struct tm const *tm = time2tm(unixtime, RCSversiontm_year + ((unsigned)tm->tm_year < 100 ? 0 : 1900), tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec ); } /* Like str2time, except die if an error was found. */ static time_t str2time_checked P((char const*,time_t,long)); static time_t str2time_checked(source, default_time, default_zone) char const *source; time_t default_time; long default_zone; { time_t t = str2time(source, default_time, default_zone); if (t == -1) faterror("unknown date/time: %s", source); return t; } /* * Parse a free-format date in SOURCE, convert it * into RCS internal format, and store the result into TARGET. */ void str2date(source, target) char const *source; char target[datesize]; { time2date( str2time_checked(source, now(), use_zone_offset ? zone_offset : RCSversiontm_year + 1900, z->tm_mon + 1, z->tm_mday, z->tm_hour, z->tm_min, z->tm_sec, c, (int) (zone / (60*60)) ); if ((non_hour = zone % (60*60))) { # if has_printf_dot static char const fmt[] = ":%.2d"; # else static char const fmt[] = ":%02d"; # endif VOID sprintf(datebuf + strlen(datebuf), fmt, non_hour / 60); if ((non_hour %= 60)) VOID sprintf(datebuf + strlen(datebuf), fmt, non_hour); } } return datebuf; }