1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 package org.iotivity.service.tm;
23 import android.util.Log;
26 * This class provides time-related information used for scheduled/recursive
27 * group action features. Along with time-related variables, it also provides
28 * various useful functionality including translating time to second unit
32 public enum ActionSetType {
33 NONE, SCHEDULED, RECURSIVE
37 public int mMonth = 0;
42 public int mDayOfWeek = 0;
44 private ActionSetType mType = ActionSetType.NONE;
45 private long mDelay = 0;
47 private final String LOG_TAG = this.getClass().getSimpleName();
50 * Set the time for executing ActionSet.
55 * Month of the year to be set
57 * Day of the month to be set
65 * Day of the week to be set
67 public void setTime(int year, int month, int day, int hour, int min,
68 int sec, int dayOfTheWeek) {
69 if (year < 0 || month < 0 || day < 0 || hour < 0 || min < 0 || sec < 0
70 || dayOfTheWeek < 0) {
71 Log.e(LOG_TAG, "Input time is invalid");
85 mDayOfWeek = dayOfTheWeek;
86 mType = ActionSetType.NONE;
90 * Set type of ActionSet.
95 public void setType(ActionSetType type) {
100 * Set day of the week for recursively executing ActionSet.
105 public void setDayOfWeekForRecursive(int day) {
107 mType = ActionSetType.RECURSIVE;
108 setTime(0, 0, 0, 0, 0, 0, day);
113 * Set the time delay in seconds for executing ActionSet.
116 * time delay in seconds
118 public void setDelay(long seconds) {
119 if (mType != ActionSetType.NONE) {
125 * Get absolute time in seconds.
127 * @return long - Absolute time in seconds.
129 public long getSecAbsTime() {
132 interval = (mHour * 60 * 60);
133 interval += (mMin * 60);
134 interval += (mSec * 1);
140 * Get the type of ActionSet.
142 * @return ActionSetType - Type of ActionSet.
144 public ActionSetType getType() {
149 * Get the time delay in seconds set in the ActionSet.
151 * @return long - Delay in seconds.
153 public long getDelay() {