Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

.\"     $NetBSD: clock.9,v 1.2 2014/12/26 14:15:18 wiz Exp $
.\"
.\" Copyright (c) 2014 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is contributed to The NetBSD Foundation by Kamil Rytarowski
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd December 26, 2014
.Dt CLOCK 9
.Os
.Sh NAME
.Nm days_in_month ,
.Nm is_leap_year ,
.Nm days_per_year
.Nd handy time utilities
.Sh SYNOPSIS
.In sys/clock.h
.Vt #define SECS_PER_MINUTE         60
.Vt #define SECS_PER_HOUR           3600
.Vt #define SECS_PER_DAY            86400
.Vt #define DAYS_PER_COMMON_YEAR    365
.Vt #define DAYS_PER_LEAP_YEAR      366
.Vt #define SECS_PER_COMMON_YEAR    (SECS_PER_DAY * DAYS_PER_COMMON_YEAR)
.Vt #define SECS_PER_LEAP_YEAR      (SECS_PER_DAY * DAYS_PER_LEAP_YEAR)
.Ft static inline int
.Fn days_in_month "int m"
.Ft static inline int
.Fn is_leap_year "uint64_t year"
.Ft static inline int
.Fn days_per_year "uint64_t year"
.Sh DESCRIPTION
The
.In sys/clock.h
file provides handy time constants and
.Ft static inline
functions.
.Sh FUNCTIONS
The
.Fn days_in_month
function returns the number of days in the given month.
.Fn days_in_month
assumes 28 days for February.
If the input value is out of the valid range (1-12) then the function returns
\-1.
.Pp
The
.Fn is_leap_year
and
.Fn days_per_year
functions take as the input parameter a value in the Gregorian year format.
.Sh SEE ALSO
.Xr bintime 9 ,
.Xr boottime 9 ,
.Xr time_second 9 ,
.Xr time_uptime 9 ,
.Xr todr_gettime 9
.Sh HISTORY
The
.In sys/clock.h
header with handy utilities originated from
.In dev/clock_subr.h ,
which originated from
.In arch/hp300/hp300/clock.c .
.Pp
The
.In arch/hp300/hp300/clock.c
file first appeared in
.Nx 0.8
as a set of hp300 time-converting functions.
.In dev/clock_subr.h
first appeared in
.Nx 1.3
as a shared list of functions to convert between
.Dq year/month/day/hour/minute/second
and seconds since 1970
.Pq Dq POSIX time .
The
.In sys/clock.h
file first appeared in
.Nx 8 .
.Sh AUTHORS
.An Kamil Rytarowski