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)
27 curr = localtime(&now);
36 time_t stc_time_get_week_start(time_t now)
41 curr = localtime(&now);
47 if (curr->tm_wday > 1)
48 days = curr->tm_wday - 1;
50 days = 1 - curr->tm_wday;
52 return (mktime(curr) - (days * SEC_IN_DAY));
55 time_t stc_time_get_month_start(time_t now, int month_start_date)
60 curr = localtime(&now);
66 if (curr->tm_mday < month_start_date) {
68 if (curr->tm_mon < 0) {
74 is_leap_year = ((curr->tm_year + 1900) % 4 ? 0 : 1);
75 curr->tm_mday = month_start_date;
77 switch (month_start_date) {
80 if (curr->tm_mon == 1 && !is_leap_year)
83 else if (curr->tm_mon == 1 && is_leap_year)
88 if (curr->tm_mon == 1 && !is_leap_year)
91 else if (curr->tm_mon == 1 && is_leap_year)
94 else if (curr->tm_mon == 3 || curr->tm_mon == 5 ||
95 curr->tm_mon == 8 || curr->tm_mon == 10)