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)
43 res = localtime_r(&now, &curr);
50 days = curr.tm_wday - 1;
52 days = 1 - curr.tm_wday;
54 return (mktime(&curr) - (days * SEC_IN_DAY));
57 time_t stc_time_get_month_start(time_t now, int month_start_date)
62 curr = localtime(&now);
68 if (curr->tm_mday < month_start_date) {
70 if (curr->tm_mon < 0) {
76 is_leap_year = ((curr->tm_year + 1900) % 4 ? 0 : 1);
77 curr->tm_mday = month_start_date;
79 switch (month_start_date) {
82 if (curr->tm_mon == 1 && !is_leap_year)
85 else if (curr->tm_mon == 1 && is_leap_year)
90 if (curr->tm_mon == 1 && !is_leap_year)
93 else if (curr->tm_mon == 1 && is_leap_year)
96 else if (curr->tm_mon == 3 || curr->tm_mon == 5 ||
97 curr->tm_mon == 8 || curr->tm_mon == 10)