2015-04-08 14:56:43 +02:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/time/lib_dayofweek.c
|
2015-04-08 14:56:43 +02:00
|
|
|
*
|
2021-03-20 19:59:50 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-04-08 14:56:43 +02:00
|
|
|
*
|
2021-03-20 19:59:50 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-08 14:56:43 +02:00
|
|
|
*
|
2021-03-20 19:59:50 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-04-08 14:56:43 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2023-06-24 21:04:06 +02:00
|
|
|
#include <nuttx/clock.h>
|
2015-04-08 14:56:43 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Declarations
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Constant Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2015-04-08 14:56:43 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-02-22 01:08:58 +01:00
|
|
|
* Private Data
|
2015-04-08 14:56:43 +02:00
|
|
|
****************************************************************************/
|
2015-04-08 15:02:13 +02:00
|
|
|
|
2015-04-08 14:56:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: clock_dayoftheweek
|
2015-04-08 14:56:43 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the day of the week
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* mday - The day of the month 1 - 31
|
|
|
|
* month - The month of the year 1 - 12
|
|
|
|
* year - the year including the 1900
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2015-04-08 15:02:13 +02:00
|
|
|
* Zero based day of the week 0-6, 0 = Sunday, 1 = Monday... 6 = Saturday
|
2015-04-08 14:56:43 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int clock_dayoftheweek(int mday, int month, int year)
|
|
|
|
{
|
2015-04-08 15:02:13 +02:00
|
|
|
if (month <= 2)
|
|
|
|
{
|
2015-04-08 14:56:43 +02:00
|
|
|
year--;
|
|
|
|
month += 12;
|
2015-04-08 15:02:13 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 14:56:43 +02:00
|
|
|
month -= 2;
|
2015-10-12 15:45:02 +02:00
|
|
|
return (mday + year + year / 4 - year / 100 + year / 400 +
|
|
|
|
(31 * month) / 12) % 7;
|
2015-04-08 14:56:43 +02:00
|
|
|
}
|