12f8d7c56SGarance A Drosehn /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 31de7b4b8SPedro F. Giffuni * 42f8d7c56SGarance A Drosehn * ------+---------+---------+---------+---------+---------+---------+---------* 52f8d7c56SGarance A Drosehn * Copyright (c) 2003 - Garance Alistair Drosehn <gad@FreeBSD.org>. 62f8d7c56SGarance A Drosehn * All rights reserved. 72f8d7c56SGarance A Drosehn * 82f8d7c56SGarance A Drosehn * Redistribution and use in source and binary forms, with or without 92f8d7c56SGarance A Drosehn * modification, are permitted provided that the following conditions 102f8d7c56SGarance A Drosehn * are met: 112f8d7c56SGarance A Drosehn * 1. Redistributions of source code must retain the above copyright 122f8d7c56SGarance A Drosehn * notice, this list of conditions and the following disclaimer. 132f8d7c56SGarance A Drosehn * 2. Redistributions in binary form must reproduce the above copyright 142f8d7c56SGarance A Drosehn * notice, this list of conditions and the following disclaimer in the 152f8d7c56SGarance A Drosehn * documentation and/or other materials provided with the distribution. 162f8d7c56SGarance A Drosehn * 172f8d7c56SGarance A Drosehn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 182f8d7c56SGarance A Drosehn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 192f8d7c56SGarance A Drosehn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 202f8d7c56SGarance A Drosehn * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 212f8d7c56SGarance A Drosehn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 222f8d7c56SGarance A Drosehn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 232f8d7c56SGarance A Drosehn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 242f8d7c56SGarance A Drosehn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 252f8d7c56SGarance A Drosehn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 262f8d7c56SGarance A Drosehn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 272f8d7c56SGarance A Drosehn * SUCH DAMAGE. 282f8d7c56SGarance A Drosehn * 292f8d7c56SGarance A Drosehn * The views and conclusions contained in the software and documentation 302f8d7c56SGarance A Drosehn * are those of the authors and should not be interpreted as representing 312f8d7c56SGarance A Drosehn * official policies, either expressed or implied, of the FreeBSD Project. 322f8d7c56SGarance A Drosehn * 332f8d7c56SGarance A Drosehn * ------+---------+---------+---------+---------+---------+---------+---------* 342f8d7c56SGarance A Drosehn * ------+---------+---------+---------+---------+---------+---------+---------* 352f8d7c56SGarance A Drosehn */ 362f8d7c56SGarance A Drosehn 372f8d7c56SGarance A Drosehn #include <sys/cdefs.h> 382f8d7c56SGarance A Drosehn #include <time.h> 392f8d7c56SGarance A Drosehn 406a1485e2SGarance A Drosehn #define PTM_PARSE_ISO8601 0x0001 /* Parse ISO-standard format */ 416a1485e2SGarance A Drosehn #define PTM_PARSE_DWM 0x0002 /* Parse Day-Week-Month format */ 426a1485e2SGarance A Drosehn #define PTM_PARSE_MATCHDOM 0x0004 /* If the user specifies a day-of-month, 436a1485e2SGarance A Drosehn * then the result should be a month 446a1485e2SGarance A Drosehn * which actually has that day. Eg: 456a1485e2SGarance A Drosehn * the user requests "day 31" when 466a1485e2SGarance A Drosehn * the present month is February. */ 476a1485e2SGarance A Drosehn 486a1485e2SGarance A Drosehn struct ptime_data; 496a1485e2SGarance A Drosehn 506a1485e2SGarance A Drosehn /* Some global variables from newsyslog.c which might be of interest */ 516a1485e2SGarance A Drosehn extern int dbg_at_times; /* cmdline debugging option */ 522f8d7c56SGarance A Drosehn extern int noaction; /* command-line option */ 532f8d7c56SGarance A Drosehn extern int verbose; /* command-line option */ 546a1485e2SGarance A Drosehn extern struct ptime_data *dbg_timenow; 552f8d7c56SGarance A Drosehn 562f8d7c56SGarance A Drosehn __BEGIN_DECLS 576a1485e2SGarance A Drosehn struct ptime_data *ptime_init(const struct ptime_data *_optsrc); 586a1485e2SGarance A Drosehn int ptime_adjust4dst(struct ptime_data *_ptime, const struct 596a1485e2SGarance A Drosehn ptime_data *_dstsrc); 606a1485e2SGarance A Drosehn int ptime_free(struct ptime_data *_ptime); 616a1485e2SGarance A Drosehn int ptime_relparse(struct ptime_data *_ptime, int _parseopts, 626a1485e2SGarance A Drosehn time_t _basetime, const char *_str); 636a1485e2SGarance A Drosehn const char *ptimeget_ctime(const struct ptime_data *_ptime); 64b326fec4SDavid Bright char *ptimeget_ctime_rfc5424(const struct ptime_data *_ptime, 65b326fec4SDavid Bright char *timebuf, size_t bufsize); 666a1485e2SGarance A Drosehn double ptimeget_diff(const struct ptime_data *_minuend, 676a1485e2SGarance A Drosehn const struct ptime_data *_subtrahend); 686a1485e2SGarance A Drosehn time_t ptimeget_secs(const struct ptime_data *_ptime); 696a1485e2SGarance A Drosehn int ptimeset_nxtime(struct ptime_data *_ptime); 706a1485e2SGarance A Drosehn int ptimeset_time(struct ptime_data *_ptime, time_t _secs); 712f8d7c56SGarance A Drosehn __END_DECLS 72