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);
37 time_t stc_time_get_week_start(time_t now)
42 curr = localtime(&now);
48 if (curr->tm_wday > 1)
49 days = curr->tm_wday - 1;
51 days = 1 - curr->tm_wday;
53 return (mktime(curr) - (days * SEC_IN_DAY));
56 time_t stc_time_get_month_start(time_t now, int month_start_date)
61 curr = localtime(&now);
67 if (curr->tm_mday < month_start_date) {
69 if (curr->tm_mon < 0) {
75 is_leap_year = ((curr->tm_year + 1900) % 4 ? 0 : 1);
76 curr->tm_mday = month_start_date;
78 switch (month_start_date) {
81 if (curr->tm_mon == 1 && !is_leap_year)
84 else if (curr->tm_mon == 1 && is_leap_year)
89 if (curr->tm_mon == 1 && !is_leap_year)
92 else if (curr->tm_mon == 1 && is_leap_year)
95 else if (curr->tm_mon == 3 || curr->tm_mon == 5 ||
96 curr->tm_mon == 8 || curr->tm_mon == 10)