1238104Sdes/* 2238104Sdes * $Id: duration.h 4341 2011-01-31 15:21:09Z matthijs $ 3238104Sdes * 4238104Sdes * Copyright (c) 2009 NLNet Labs. All rights reserved. 5238104Sdes * 6238104Sdes * Redistribution and use in source and binary forms, with or without 7238104Sdes * modification, are permitted provided that the following conditions 8238104Sdes * are met: 9238104Sdes * 1. Redistributions of source code must retain the above copyright 10238104Sdes * notice, this list of conditions and the following disclaimer. 11238104Sdes * 2. Redistributions in binary form must reproduce the above copyright 12238104Sdes * notice, this list of conditions and the following disclaimer in the 13238104Sdes * documentation and/or other materials provided with the distribution. 14238104Sdes * 15238104Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16238104Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17238104Sdes * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18238104Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 19238104Sdes * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20238104Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21238104Sdes * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22238104Sdes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23238104Sdes * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24238104Sdes * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25238104Sdes * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26238104Sdes * 27238104Sdes */ 28238104Sdes 29238104Sdes/** 30238104Sdes * 31238104Sdes * This file is copied from the OpenDNSSEC source repository 32238104Sdes * and only slightly adapted to make it fit. 33238104Sdes */ 34238104Sdes 35238104Sdes/** 36238104Sdes * 37238104Sdes * Durations. 38238104Sdes */ 39238104Sdes 40238104Sdes#ifndef LDNS_DURATION_H 41238104Sdes#define LDNS_DURATION_H 42238104Sdes 43238104Sdes#include <stdint.h> 44238104Sdes#include <time.h> 45238104Sdes 46238104Sdes/** 47238104Sdes * Duration. 48238104Sdes * 49238104Sdes */ 50238104Sdestypedef struct ldns_duration_struct ldns_duration_type; 51238104Sdesstruct ldns_duration_struct 52238104Sdes{ 53238104Sdes time_t years; 54238104Sdes time_t months; 55238104Sdes time_t weeks; 56238104Sdes time_t days; 57238104Sdes time_t hours; 58238104Sdes time_t minutes; 59238104Sdes time_t seconds; 60238104Sdes}; 61238104Sdes 62238104Sdes/** 63238104Sdes * Create a new 'instant' duration. 64238104Sdes * \return ldns_duration_type* created duration 65238104Sdes * 66238104Sdes */ 67238104Sdesldns_duration_type* ldns_duration_create(void); 68238104Sdes 69238104Sdes/** 70238104Sdes * Compare durations. 71238104Sdes * \param[in] d1 one duration 72238104Sdes * \param[in] d2 another duration 73238104Sdes * \return int 0 if equal, -1 if d1 < d2, 1 if d2 < d1 74238104Sdes * 75238104Sdes */ 76238104Sdesint ldns_duration_compare(ldns_duration_type* d1, ldns_duration_type* d2); 77238104Sdes 78238104Sdes/** 79238104Sdes * Create a duration from string. 80238104Sdes * \param[in] str string-format duration 81238104Sdes * \return ldns_duration_type* created duration 82238104Sdes * 83238104Sdes */ 84238104Sdesldns_duration_type* ldns_duration_create_from_string(const char* str); 85238104Sdes 86238104Sdes/** 87238104Sdes * Convert a duration to a string. 88238104Sdes * \param[in] duration duration to be converted 89238104Sdes * \return char* string-format duration 90238104Sdes * 91238104Sdes */ 92238104Sdeschar* ldns_duration2string(ldns_duration_type* duration); 93238104Sdes 94238104Sdes/** 95238104Sdes * Convert a duration to a time. 96238104Sdes * \param[in] duration duration to be converted 97238104Sdes * \return time_t time-format duration 98238104Sdes * 99238104Sdes */ 100238104Sdestime_t ldns_duration2time(ldns_duration_type* duration); 101238104Sdes 102238104Sdes/** 103238104Sdes * Clean up duration. 104238104Sdes * \param[in] duration duration to be cleaned up 105238104Sdes * 106238104Sdes */ 107238104Sdesvoid ldns_duration_cleanup(ldns_duration_type* duration); 108238104Sdes 109238104Sdes#endif /* LDNS_DURATION_H */ 110