1.\" $NetBSD: clock.9,v 1.2 2014/12/26 14:15:18 wiz Exp $ 2.\" 3.\" Copyright (c) 2014 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is contributed to The NetBSD Foundation by Kamil Rytarowski 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" POSSIBILITY OF SUCH DAMAGE. 28.\" 29.Dd December 26, 2014 30.Dt CLOCK 9 31.Os 32.Sh NAME 33.Nm days_in_month , 34.Nm is_leap_year , 35.Nm days_per_year 36.Nd handy time utilities 37.Sh SYNOPSIS 38.In sys/clock.h 39.Vt #define SECS_PER_MINUTE 60 40.Vt #define SECS_PER_HOUR 3600 41.Vt #define SECS_PER_DAY 86400 42.Vt #define DAYS_PER_COMMON_YEAR 365 43.Vt #define DAYS_PER_LEAP_YEAR 366 44.Vt #define SECS_PER_COMMON_YEAR (SECS_PER_DAY * DAYS_PER_COMMON_YEAR) 45.Vt #define SECS_PER_LEAP_YEAR (SECS_PER_DAY * DAYS_PER_LEAP_YEAR) 46.Ft static inline int 47.Fn days_in_month "int m" 48.Ft static inline int 49.Fn is_leap_year "uint64_t year" 50.Ft static inline int 51.Fn days_per_year "uint64_t year" 52.Sh DESCRIPTION 53The 54.In sys/clock.h 55file provides handy time constants and 56.Ft static inline 57functions. 58.Sh FUNCTIONS 59The 60.Fn days_in_month 61function returns the number of days in the given month. 62.Fn days_in_month 63assumes 28 days for February. 64If the input value is out of the valid range (1-12) then the function returns 65\-1. 66.Pp 67The 68.Fn is_leap_year 69and 70.Fn days_per_year 71functions take as the input parameter a value in the Gregorian year format. 72.Sh SEE ALSO 73.Xr bintime 9 , 74.Xr boottime 9 , 75.Xr time_second 9 , 76.Xr time_uptime 9 , 77.Xr todr_gettime 9 78.Sh HISTORY 79The 80.In sys/clock.h 81header with handy utilities originated from 82.In dev/clock_subr.h , 83which originated from 84.In arch/hp300/hp300/clock.c . 85.Pp 86The 87.In arch/hp300/hp300/clock.c 88file first appeared in 89.Nx 0.8 90as a set of hp300 time-converting functions. 91.In dev/clock_subr.h 92first appeared in 93.Nx 1.3 94as a shared list of functions to convert between 95.Dq year/month/day/hour/minute/second 96and seconds since 1970 97.Pq Dq POSIX time . 98The 99.In sys/clock.h 100file first appeared in 101.Nx 8 . 102.Sh AUTHORS 103.An Kamil Rytarowski 104