2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #define SEC_IN_DAY 24 * 60 * 60
21 #define SEC_IN_WEEK 7 * SEC_IN_DAY
23 time_t stc_time_get_day_start(time_t now)
28 res = localtime_r(&now, &curr);
39 time_t stc_time_get_week_start(time_t now)
45 res = localtime_r(&now, &curr);
54 days = curr.tm_wday - 1;
56 days = 1 - curr.tm_wday;
58 return (mktime(&curr) - (days * SEC_IN_DAY));
61 time_t stc_time_get_month_start(time_t now, int month_start_date)
67 res = localtime_r(&now, &curr);
75 if (curr.tm_mday < month_start_date) {
77 if (curr.tm_mon < 0) {
83 is_leap_year = ((curr.tm_year + 1900) % 4 ? 0 : 1);
84 curr.tm_mday = month_start_date;
86 switch (month_start_date) {
89 if (curr.tm_mon == 1 && !is_leap_year)
92 else if (curr.tm_mon == 1 && is_leap_year)
97 if (curr.tm_mon == 1 && !is_leap_year)
100 else if (curr.tm_mon == 1 && is_leap_year)
103 else if (curr.tm_mon == 3 || curr.tm_mon == 5 ||
104 curr.tm_mon == 8 || curr.tm_mon == 10)
112 return mktime(&curr);