@ray-js/lamp-schedule-core 1.0.0-beta-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +565 -0
  2. package/lib/config/dpCodes.d.ts +27 -0
  3. package/lib/config/dpCodes.js +30 -0
  4. package/lib/config/index.d.ts +2 -0
  5. package/lib/config/index.js +2 -0
  6. package/lib/config/rhythms/defaultValue.d.ts +18 -0
  7. package/lib/config/rhythms/defaultValue.js +72 -0
  8. package/lib/config/rhythms/index.d.ts +10 -0
  9. package/lib/config/rhythms/index.js +35 -0
  10. package/lib/conflict/ConflictResolver.d.ts +2 -0
  11. package/lib/conflict/ConflictResolver.js +284 -0
  12. package/lib/conflict/__test__/ConflictResolver.test.d.ts +1 -0
  13. package/lib/conflict/__test__/ConflictResolver.test.js +183 -0
  14. package/lib/conflict/__test__/index.test.d.ts +1 -0
  15. package/lib/conflict/__test__/index.test.js +385 -0
  16. package/lib/conflict/__test__/scheduleDataManager.test.d.ts +1 -0
  17. package/lib/conflict/__test__/scheduleDataManager.test.js +170 -0
  18. package/lib/conflict/__test__/transform.test.d.ts +1 -0
  19. package/lib/conflict/__test__/transform.test.js +454 -0
  20. package/lib/conflict/__test__/updateDeviceDp.d.ts +1 -0
  21. package/lib/conflict/__test__/updateDeviceDp.js +114 -0
  22. package/lib/conflict/index.d.ts +42 -0
  23. package/lib/conflict/index.js +103 -0
  24. package/lib/conflict/scheduleDataManager.d.ts +12 -0
  25. package/lib/conflict/scheduleDataManager.js +79 -0
  26. package/lib/conflict/transform.d.ts +71 -0
  27. package/lib/conflict/transform.js +251 -0
  28. package/lib/conflict/type.d.ts +55 -0
  29. package/lib/conflict/type.js +17 -0
  30. package/lib/conflict/updateDeviceDp.d.ts +1 -0
  31. package/lib/conflict/updateDeviceDp.js +41 -0
  32. package/lib/constant/index.d.ts +5 -0
  33. package/lib/constant/index.js +5 -0
  34. package/lib/context/index.d.ts +3 -0
  35. package/lib/context/index.js +3 -0
  36. package/lib/context/rhythms/actions.d.ts +20 -0
  37. package/lib/context/rhythms/actions.js +52 -0
  38. package/lib/context/rhythms/index.d.ts +5 -0
  39. package/lib/context/rhythms/index.js +51 -0
  40. package/lib/context/rhythms/reducer.d.ts +24 -0
  41. package/lib/context/rhythms/reducer.js +38 -0
  42. package/lib/context/schedule/actions.d.ts +7 -0
  43. package/lib/context/schedule/actions.js +51 -0
  44. package/lib/context/schedule/context.d.ts +6 -0
  45. package/lib/context/schedule/context.js +52 -0
  46. package/lib/context/schedule/index.d.ts +1 -0
  47. package/lib/context/schedule/index.js +1 -0
  48. package/lib/context/schedule/reducer.d.ts +16 -0
  49. package/lib/context/schedule/reducer.js +104 -0
  50. package/lib/context/schedule/type.d.ts +41 -0
  51. package/lib/context/schedule/type.js +11 -0
  52. package/lib/context/timer/actions.d.ts +8 -0
  53. package/lib/context/timer/actions.js +52 -0
  54. package/lib/context/timer/context.d.ts +10 -0
  55. package/lib/context/timer/context.js +53 -0
  56. package/lib/context/timer/index.d.ts +1 -0
  57. package/lib/context/timer/index.js +1 -0
  58. package/lib/context/timer/reducer.d.ts +15 -0
  59. package/lib/context/timer/reducer.js +70 -0
  60. package/lib/context/timer/type.d.ts +46 -0
  61. package/lib/context/timer/type.js +24 -0
  62. package/lib/dpParser/README.md +63 -0
  63. package/lib/dpParser/__test__/cycle.test.d.ts +1 -0
  64. package/lib/dpParser/__test__/cycle.test.js +258 -0
  65. package/lib/dpParser/__test__/random.test.d.ts +1 -0
  66. package/lib/dpParser/__test__/random.test.js +211 -0
  67. package/lib/dpParser/__test__/rhythms.test.d.ts +1 -0
  68. package/lib/dpParser/__test__/rhythms.test.js +71 -0
  69. package/lib/dpParser/__test__/rtcTimer.test.d.ts +1 -0
  70. package/lib/dpParser/__test__/rtcTimer.test.js +235 -0
  71. package/lib/dpParser/__test__/sleep.test.d.ts +1 -0
  72. package/lib/dpParser/__test__/sleep.test.js +71 -0
  73. package/lib/dpParser/__test__/sleepCommon.test.d.ts +1 -0
  74. package/lib/dpParser/__test__/sleepCommon.test.js +197 -0
  75. package/lib/dpParser/__test__/timerReport.test.d.ts +1 -0
  76. package/lib/dpParser/__test__/timerReport.test.js +100 -0
  77. package/lib/dpParser/__test__/wakeup.test.d.ts +1 -0
  78. package/lib/dpParser/__test__/wakeup.test.js +69 -0
  79. package/lib/dpParser/__test__/wakeupCommon.test.d.ts +1 -0
  80. package/lib/dpParser/__test__/wakeupCommon.test.js +131 -0
  81. package/lib/dpParser/cycle/index.d.ts +15 -0
  82. package/lib/dpParser/cycle/index.js +134 -0
  83. package/lib/dpParser/index.d.ts +23 -0
  84. package/lib/dpParser/index.js +43 -0
  85. package/lib/dpParser/random/index.d.ts +15 -0
  86. package/lib/dpParser/random/index.js +127 -0
  87. package/lib/dpParser/rhythms.d.ts +41 -0
  88. package/lib/dpParser/rhythms.js +116 -0
  89. package/lib/dpParser/rtcTimer.d.ts +17 -0
  90. package/lib/dpParser/rtcTimer.js +300 -0
  91. package/lib/dpParser/sleep/index.d.ts +9 -0
  92. package/lib/dpParser/sleep/index.js +29 -0
  93. package/lib/dpParser/sleep/sleepCommon.d.ts +11 -0
  94. package/lib/dpParser/sleep/sleepCommon.js +117 -0
  95. package/lib/dpParser/sleep/sleepSigmesh.d.ts +0 -0
  96. package/lib/dpParser/sleep/sleepSigmesh.js +101 -0
  97. package/lib/dpParser/timerReport.d.ts +11 -0
  98. package/lib/dpParser/timerReport.js +43 -0
  99. package/lib/dpParser/utils.d.ts +27 -0
  100. package/lib/dpParser/utils.js +53 -0
  101. package/lib/dpParser/wakeup/index.d.ts +10 -0
  102. package/lib/dpParser/wakeup/index.js +34 -0
  103. package/lib/dpParser/wakeup/wakeupCommon.d.ts +11 -0
  104. package/lib/dpParser/wakeup/wakeupCommon.js +106 -0
  105. package/lib/dpParser/wakeup/wakeupSigmesh.d.ts +15 -0
  106. package/lib/dpParser/wakeup/wakeupSigmesh.js +86 -0
  107. package/lib/hooks/__test__/useCommon.test.d.ts +1 -0
  108. package/lib/hooks/__test__/useCommon.test.js +72 -0
  109. package/lib/hooks/__test__/useCountdownDp.test.d.ts +1 -0
  110. package/lib/hooks/__test__/useCountdownDp.test.js +82 -0
  111. package/lib/hooks/__test__/useCycleDp.test.d.ts +1 -0
  112. package/lib/hooks/__test__/useCycleDp.test.js +92 -0
  113. package/lib/hooks/__test__/useRandomDp.test.d.ts +1 -0
  114. package/lib/hooks/__test__/useRandomDp.test.js +88 -0
  115. package/lib/hooks/__test__/useRhythmsDp.test.d.ts +1 -0
  116. package/lib/hooks/__test__/useRhythmsDp.test.js +81 -0
  117. package/lib/hooks/__test__/useSleepDp.test.d.ts +1 -0
  118. package/lib/hooks/__test__/useSleepDp.test.js +127 -0
  119. package/lib/hooks/__test__/useTimeFlush.test.d.ts +1 -0
  120. package/lib/hooks/__test__/useTimeFlush.test.js +109 -0
  121. package/lib/hooks/__test__/useTimerDp.test.d.ts +1 -0
  122. package/lib/hooks/__test__/useTimerDp.test.js +79 -0
  123. package/lib/hooks/__test__/useTimerOperate.test.d.ts +1 -0
  124. package/lib/hooks/__test__/useTimerOperate.test.js +286 -0
  125. package/lib/hooks/__test__/useTimerOperateCloud.test.d.ts +1 -0
  126. package/lib/hooks/__test__/useTimerOperateCloud.test.js +190 -0
  127. package/lib/hooks/__test__/useTimerOperateLocal.test.d.ts +1 -0
  128. package/lib/hooks/__test__/useTimerOperateLocal.test.js +216 -0
  129. package/lib/hooks/__test__/useTimerReportDp.test.d.ts +1 -0
  130. package/lib/hooks/__test__/useTimerReportDp.test.js +93 -0
  131. package/lib/hooks/__test__/useTimerSupport.test.d.ts +1 -0
  132. package/lib/hooks/__test__/useTimerSupport.test.js +110 -0
  133. package/lib/hooks/__test__/useWakeUpDp.test.d.ts +1 -0
  134. package/lib/hooks/__test__/useWakeUpDp.test.js +129 -0
  135. package/lib/hooks/useBaseLightDp.d.ts +21 -0
  136. package/lib/hooks/useBaseLightDp.js +165 -0
  137. package/lib/hooks/useCommon.d.ts +29 -0
  138. package/lib/hooks/useCommon.js +59 -0
  139. package/lib/hooks/useCommonSupport.d.ts +25 -0
  140. package/lib/hooks/useCommonSupport.js +241 -0
  141. package/lib/hooks/useCountdownDp.d.ts +13 -0
  142. package/lib/hooks/useCountdownDp.js +28 -0
  143. package/lib/hooks/useCountdownSupport.d.ts +9 -0
  144. package/lib/hooks/useCountdownSupport.js +13 -0
  145. package/lib/hooks/useCycleDp.d.ts +7 -0
  146. package/lib/hooks/useCycleDp.js +21 -0
  147. package/lib/hooks/useCycleSupport.d.ts +12 -0
  148. package/lib/hooks/useCycleSupport.js +16 -0
  149. package/lib/hooks/useRandomDp.d.ts +7 -0
  150. package/lib/hooks/useRandomDp.js +21 -0
  151. package/lib/hooks/useRandomSupport.d.ts +12 -0
  152. package/lib/hooks/useRandomSupport.js +16 -0
  153. package/lib/hooks/useRhythmsDp.d.ts +7 -0
  154. package/lib/hooks/useRhythmsDp.js +23 -0
  155. package/lib/hooks/useSleepDp.d.ts +6 -0
  156. package/lib/hooks/useSleepDp.js +21 -0
  157. package/lib/hooks/useSleepSupport.d.ts +8 -0
  158. package/lib/hooks/useSleepSupport.js +13 -0
  159. package/lib/hooks/useTimeFlush.d.ts +8 -0
  160. package/lib/hooks/useTimeFlush.js +31 -0
  161. package/lib/hooks/useTimerDp.d.ts +5 -0
  162. package/lib/hooks/useTimerDp.js +25 -0
  163. package/lib/hooks/useTimerFlushList.d.ts +11 -0
  164. package/lib/hooks/useTimerFlushList.js +53 -0
  165. package/lib/hooks/useTimerOperate.d.ts +68 -0
  166. package/lib/hooks/useTimerOperate.js +403 -0
  167. package/lib/hooks/useTimerOperateCloud.d.ts +31 -0
  168. package/lib/hooks/useTimerOperateCloud.js +233 -0
  169. package/lib/hooks/useTimerOperateLocal.d.ts +40 -0
  170. package/lib/hooks/useTimerOperateLocal.js +310 -0
  171. package/lib/hooks/useTimerReportDp.d.ts +15 -0
  172. package/lib/hooks/useTimerReportDp.js +48 -0
  173. package/lib/hooks/useTimerSupport.d.ts +13 -0
  174. package/lib/hooks/useTimerSupport.js +38 -0
  175. package/lib/hooks/useWakeUpDp.d.ts +6 -0
  176. package/lib/hooks/useWakeUpDp.js +21 -0
  177. package/lib/hooks/useWakeUpSupport.d.ts +8 -0
  178. package/lib/hooks/useWakeUpSupport.js +13 -0
  179. package/lib/hooks/useWakeupDp.d.ts +6 -0
  180. package/lib/hooks/useWakeupDp.js +21 -0
  181. package/lib/hooks/useWakeupSupport.d.ts +8 -0
  182. package/lib/hooks/useWakeupSupport.js +13 -0
  183. package/lib/i18n/index.d.ts +142 -0
  184. package/lib/i18n/index.js +7 -0
  185. package/lib/i18n/rhythms.d.ts +73 -0
  186. package/lib/i18n/rhythms.js +72 -0
  187. package/lib/i18n/strings.d.ts +73 -0
  188. package/lib/i18n/strings.js +6 -0
  189. package/lib/index.d.ts +51 -0
  190. package/lib/index.js +64 -0
  191. package/lib/types/countdown.d.ts +3 -0
  192. package/lib/types/countdown.js +1 -0
  193. package/lib/types/cycle.d.ts +22 -0
  194. package/lib/types/cycle.js +1 -0
  195. package/lib/types/global.d.ts +9 -0
  196. package/lib/types/index.d.ts +331 -0
  197. package/lib/types/index.js +76 -0
  198. package/lib/types/random.d.ts +20 -0
  199. package/lib/types/random.js +1 -0
  200. package/lib/types/rhythms.d.ts +79 -0
  201. package/lib/types/rhythms.js +15 -0
  202. package/lib/types/sleep.d.ts +36 -0
  203. package/lib/types/sleep.js +1 -0
  204. package/lib/types/timer.d.ts +107 -0
  205. package/lib/types/timer.js +1 -0
  206. package/lib/types/wakeup.d.ts +38 -0
  207. package/lib/types/wakeup.js +1 -0
  208. package/lib/utils/ScheduleCache.d.ts +19 -0
  209. package/lib/utils/ScheduleCache.js +39 -0
  210. package/lib/utils/ScheduleCloudProperty.d.ts +75 -0
  211. package/lib/utils/ScheduleCloudProperty.js +220 -0
  212. package/lib/utils/ScheduleDataSync.d.ts +82 -0
  213. package/lib/utils/ScheduleDataSync.js +127 -0
  214. package/lib/utils/ScheduleEmit.d.ts +67 -0
  215. package/lib/utils/ScheduleEmit.js +61 -0
  216. package/lib/utils/ScheduleLogger.d.ts +19 -0
  217. package/lib/utils/ScheduleLogger.js +71 -0
  218. package/lib/utils/ScheduleSupport.d.ts +131 -0
  219. package/lib/utils/ScheduleSupport.js +373 -0
  220. package/lib/utils/ScheduleUtils.d.ts +12 -0
  221. package/lib/utils/ScheduleUtils.js +51 -0
  222. package/lib/utils/__test__/ScheduleCloudProperty.test.d.ts +1 -0
  223. package/lib/utils/__test__/ScheduleCloudProperty.test.js +320 -0
  224. package/lib/utils/__test__/ScheduleSupport.test.d.ts +1 -0
  225. package/lib/utils/__test__/ScheduleSupport.test.js +211 -0
  226. package/lib/utils/__test__/ScheduleUtils.test.d.ts +1 -0
  227. package/lib/utils/__test__/ScheduleUtils.test.js +119 -0
  228. package/lib/utils/__test__/common.test.d.ts +1 -0
  229. package/lib/utils/__test__/common.test.js +147 -0
  230. package/lib/utils/__test__/storage.test.d.ts +1 -0
  231. package/lib/utils/__test__/storage.test.js +98 -0
  232. package/lib/utils/__test__/time.test.d.ts +1 -0
  233. package/lib/utils/__test__/time.test.js +146 -0
  234. package/lib/utils/common.d.ts +23 -0
  235. package/lib/utils/common.js +109 -0
  236. package/lib/utils/dpState.d.ts +5 -0
  237. package/lib/utils/dpState.js +27 -0
  238. package/lib/utils/getCachedSystemInfo.d.ts +39 -0
  239. package/lib/utils/getCachedSystemInfo.js +20 -0
  240. package/lib/utils/isInIDE.d.ts +1 -0
  241. package/lib/utils/isInIDE.js +5 -0
  242. package/lib/utils/storage.d.ts +5 -0
  243. package/lib/utils/storage.js +32 -0
  244. package/lib/utils/time.d.ts +40 -0
  245. package/lib/utils/time.js +84 -0
  246. package/package.json +78 -0
@@ -0,0 +1,27 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.for-each.js";
3
+ import { scheduleLogger } from './ScheduleLogger';
4
+ const __dpState = {};
5
+ export const getDpState = dpCode => {
6
+ scheduleLogger.debug('getDpState', dpCode, __dpState);
7
+ return __dpState[dpCode];
8
+ };
9
+ export const setDpState = (dpCode, dpValue) => {
10
+ scheduleLogger.debug('setDpState', dpCode, dpValue);
11
+ __dpState[dpCode] = dpValue;
12
+ };
13
+ export const clearDpState = () => {
14
+ Object.keys(__dpState).forEach(dpCode => {
15
+ delete __dpState[dpCode];
16
+ });
17
+ scheduleLogger.debug('clearDpState', __dpState);
18
+ };
19
+ export const getAllDpState = () => {
20
+ scheduleLogger.debug('getAllDpState', __dpState);
21
+ return __dpState;
22
+ };
23
+ export const initDpState = function () {
24
+ let dpState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25
+ Object.assign(+new Date(), __dpState, dpState);
26
+ scheduleLogger.debug('initDpState', __dpState);
27
+ };
@@ -0,0 +1,39 @@
1
+ export type SafeArea = {
2
+ left: number;
3
+ right: number;
4
+ top: number;
5
+ bottom: number;
6
+ width: number;
7
+ height: number;
8
+ };
9
+ interface SystemInfo {
10
+ is24Hour: boolean;
11
+ system: string;
12
+ brand: string;
13
+ model: string;
14
+ platform: string;
15
+ timezoneId: string;
16
+ pixelRatio: number;
17
+ screenWidth: number;
18
+ screenHeight: number;
19
+ windowWidth: number;
20
+ windowHeight: number;
21
+ statusBarHeight: number;
22
+ language: string;
23
+ safeArea: SafeArea;
24
+ albumAuthorized: boolean;
25
+ cameraAuthorized: boolean;
26
+ locationAuthorized: boolean;
27
+ microphoneAuthorized: boolean;
28
+ notificationAuthorized: boolean;
29
+ notificationAlertAuthorized: boolean;
30
+ notificationBadgeAuthorized: boolean;
31
+ notificationSoundAuthorized: boolean;
32
+ bluetoothEnabled: boolean;
33
+ locationEnabled: boolean;
34
+ wifiEnabled: boolean;
35
+ theme?: any;
36
+ deviceOrientation?: any;
37
+ }
38
+ export declare const getCachedSystemInfo: () => SystemInfo;
39
+ export {};
@@ -0,0 +1,20 @@
1
+ import { getSystemInfoSync } from '@ray-js/ray';
2
+ import { scheduleLogger } from './ScheduleLogger';
3
+ let systemInfo = null;
4
+ let retryCount = 0;
5
+ export const getCachedSystemInfo = () => {
6
+ if (retryCount > 3) {
7
+ return {};
8
+ }
9
+ if (!systemInfo) {
10
+ retryCount++;
11
+ try {
12
+ systemInfo = getSystemInfoSync();
13
+ retryCount = 0; // 成功后重置
14
+ } catch (err) {
15
+ scheduleLogger.error('getCachedSystemInfo err:', err);
16
+ return {};
17
+ }
18
+ }
19
+ return systemInfo !== null && systemInfo !== void 0 ? systemInfo : {};
20
+ };
@@ -0,0 +1 @@
1
+ export declare const isInIDEFun: () => boolean;
@@ -0,0 +1,5 @@
1
+ import { getCachedSystemInfo } from './getCachedSystemInfo';
2
+ export const isInIDEFun = () => {
3
+ const systemInfo = getCachedSystemInfo();
4
+ return (systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.brand) === 'devtools';
5
+ };
@@ -0,0 +1,5 @@
1
+ import { SmartStorageAbility } from '@ray-js/panel-sdk';
2
+ /** 初始化 storage */
3
+ export declare const initStorage: (devId: string, groupId: string) => Promise<boolean>;
4
+ /** 获取 Storage 实例 */
5
+ export declare const getStorageIns: () => SmartStorageAbility;
@@ -0,0 +1,32 @@
1
+ import { SmartStorageAbility } from '@ray-js/panel-sdk';
2
+ import { scheduleLogger as ScheduleLogger } from './ScheduleLogger';
3
+ let _storage = null;
4
+
5
+ /** 初始化 storage */
6
+ export const initStorage = async (devId, groupId) => {
7
+ return new Promise(resolve => {
8
+ new SmartStorageAbility().init({
9
+ deviceId: devId,
10
+ groupId: groupId
11
+ }).then(storage => {
12
+ ScheduleLogger.debug('initStorage success:', storage);
13
+ _storage = storage;
14
+ resolve(true);
15
+ }).catch(err => {
16
+ ScheduleLogger.error('initStorage failed params:', {
17
+ devId,
18
+ groupId
19
+ });
20
+ ScheduleLogger.error('initStorage failed:', err);
21
+ resolve(false);
22
+ });
23
+ });
24
+ };
25
+
26
+ /** 获取 Storage 实例 */
27
+ export const getStorageIns = () => {
28
+ if (!_storage) {
29
+ ScheduleLogger.warn('storage ins is null');
30
+ }
31
+ return _storage;
32
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 获取时间 00:00 通过 时分数值
3
+ * 例如:hour = 0; minute = 30;
4
+ * 返回 00:30
5
+ */
6
+ export declare const getTimeFormatStrByHourMins: (hour: number, minute: number) => string;
7
+ export declare const getTimerStrByMinutes: (minutes: number) => string;
8
+ export declare const getTimeNumByTimeStr: (timeStr: string) => number;
9
+ /**
10
+ * 根据给定的时间和偏移量计算偏移后的时间
11
+ * 此函数用于计算给定时间前的特定分钟数的时间,主要用于需要考虑时间偏移的场景
12
+ *
13
+ * @param time - 一个字符串,表示原始时间,格式为 'HH:mm'
14
+ * @param preOffsetMins - 需要向前偏移的分钟数,用于计算最终的时间
15
+ * @returns 返回计算后的偏移时间,格式为 'HH:mm'
16
+ */
17
+ export declare const getPreOffsetTime: (time: string, preOffsetMins: number) => string;
18
+ /**
19
+ * @param hour 当前时间的小时数
20
+ * @param minute 当前时间的分钟数
21
+ * @param preOffsetMins 向前偏移量 分钟数
22
+ * @returns string 返回时间字符串 HH:mm
23
+ */
24
+ export declare const getPreOffsetTimeByHourMins: (hour: number, minute: number, preOffsetMins: number) => string;
25
+ /**
26
+ * 根据给定时间和后退偏移分钟数,计算后退后的 时间
27
+ * 此函数主要用于处理时间的后退操作,考虑到一天内的任意给定时间,如何根据特定的分钟偏移量计算出后退后的 时间
28
+ *
29
+ * @param time - 给定的时间,格式为 'HH:mm',代表一天中的某个时间点
30
+ * @param backwardOffsetMins - 后退的分钟数,必须是正数,表示要向后计算的分钟数
31
+ * @returns 返回后退后的 时间,格式为 'HH:mm'
32
+ */
33
+ export declare const getBackwardOffsetTime: (time: string, backwardOffsetMins: number) => string;
34
+ /**
35
+ * @param hour 当前时间的小时数
36
+ * @param minute 当前时间的分钟数
37
+ * @param backwardOffsetMins 向后偏移量 分钟数
38
+ * @returns string 返回时间字符串 HH:mm
39
+ */
40
+ export declare const getBackwardOffsetTimeByHourMins: (hour: number, minute: number, backwardOffsetMins: number) => string;
@@ -0,0 +1,84 @@
1
+ import dayjs from 'dayjs';
2
+
3
+ /**
4
+ * 获取时间 00:00 通过 时分数值
5
+ * 例如:hour = 0; minute = 30;
6
+ * 返回 00:30
7
+ */
8
+ export const getTimeFormatStrByHourMins = (hour, minute) => {
9
+ // 先处理分钟进位
10
+ let totalMinutes = Number(hour) * 60 + Number(minute);
11
+ // 允许负数,做 24*60 取模
12
+ totalMinutes = (totalMinutes % 1440 + 1440) % 1440;
13
+ const h = Math.floor(totalMinutes / 60);
14
+ const m = totalMinutes % 60;
15
+ const hourStr = h < 10 ? `0${h}` : `${h}`;
16
+ const minuteStr = m < 10 ? `0${m}` : `${m}`;
17
+ return `${hourStr}:${minuteStr}`;
18
+ };
19
+ export const getTimerStrByMinutes = minutes => {
20
+ const hour = Math.floor(minutes / 60);
21
+ return getTimeFormatStrByHourMins(hour, minutes % 60);
22
+ };
23
+ export const getTimeNumByTimeStr = timeStr => {
24
+ if (!timeStr || typeof timeStr !== 'string') return 0;
25
+ const [hour, minute] = timeStr.split(':');
26
+ const h = Number(hour);
27
+ const m = Number(minute);
28
+ if (isNaN(h) || isNaN(m) || h < 0 || h > 23 || m < 0 || m > 59) return 0;
29
+ return h * 60 + m;
30
+ };
31
+
32
+ /**
33
+ * 根据给定的时间和偏移量计算偏移后的时间
34
+ * 此函数用于计算给定时间前的特定分钟数的时间,主要用于需要考虑时间偏移的场景
35
+ *
36
+ * @param time - 一个字符串,表示原始时间,格式为 'HH:mm'
37
+ * @param preOffsetMins - 需要向前偏移的分钟数,用于计算最终的时间
38
+ * @returns 返回计算后的偏移时间,格式为 'HH:mm'
39
+ */
40
+ export const getPreOffsetTime = (time, preOffsetMins) => {
41
+ // 获取当前日期,格式为 'YYYY-MM-DD',用于组合日期和时间
42
+ const currentDate = dayjs().format('YYYY-MM-DD');
43
+ // 组合当前日期和给定时间,并根据偏移量计算之前的时间
44
+ const prevTime = dayjs(`${currentDate} ${time}`, 'YYYY-MM-DD HH:mm').subtract(preOffsetMins, 'minute').format('HH:mm');
45
+ // 返回计算后的偏移时间
46
+ return prevTime;
47
+ };
48
+
49
+ /**
50
+ * @param hour 当前时间的小时数
51
+ * @param minute 当前时间的分钟数
52
+ * @param preOffsetMins 向前偏移量 分钟数
53
+ * @returns string 返回时间字符串 HH:mm
54
+ */
55
+ export const getPreOffsetTimeByHourMins = (hour, minute, preOffsetMins) => {
56
+ // 将当前日期与给定时间组合,然后根据偏移量计算后退后的 时间,并格式化输出
57
+ const timeStr = getTimeFormatStrByHourMins(hour, minute);
58
+ return getPreOffsetTime(timeStr, preOffsetMins);
59
+ };
60
+
61
+ /**
62
+ * 根据给定时间和后退偏移分钟数,计算后退后的 时间
63
+ * 此函数主要用于处理时间的后退操作,考虑到一天内的任意给定时间,如何根据特定的分钟偏移量计算出后退后的 时间
64
+ *
65
+ * @param time - 给定的时间,格式为 'HH:mm',代表一天中的某个时间点
66
+ * @param backwardOffsetMins - 后退的分钟数,必须是正数,表示要向后计算的分钟数
67
+ * @returns 返回后退后的 时间,格式为 'HH:mm'
68
+ */
69
+ export const getBackwardOffsetTime = (time, backwardOffsetMins) => {
70
+ // 将当前日期与给定时间组合,然后根据偏移量计算后退后的 时间,并格式化输出
71
+ return dayjs(`${dayjs().format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm').add(backwardOffsetMins, 'minute').format('HH:mm');
72
+ };
73
+
74
+ /**
75
+ * @param hour 当前时间的小时数
76
+ * @param minute 当前时间的分钟数
77
+ * @param backwardOffsetMins 向后偏移量 分钟数
78
+ * @returns string 返回时间字符串 HH:mm
79
+ */
80
+ export const getBackwardOffsetTimeByHourMins = (hour, minute, backwardOffsetMins) => {
81
+ // 将当前日期与给定时间组合,然后根据偏移量计算后退后的 时间,并格式化输出
82
+ const timeStr = getTimeFormatStrByHourMins(hour, minute);
83
+ return getBackwardOffsetTime(timeStr, backwardOffsetMins);
84
+ };
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@ray-js/lamp-schedule-core",
3
+ "version": "1.0.0-beta-1",
4
+ "description": "照明计划模块核心能力",
5
+ "main": "./lib/index.js",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "license": "MIT",
10
+ "maintainers": [
11
+ "tuya_npm",
12
+ {
13
+ "name": "tuyafe",
14
+ "email": "tuyafe@tuya.com"
15
+ }
16
+ ],
17
+ "scripts": {
18
+ "lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
19
+ "build": "ray build --type=component",
20
+ "watch": "ray start --type=component --output ./example/src/lib",
21
+ "build:tuya": "ray build -t tuya ./example",
22
+ "build:wechat": "ray build ./example --target=wechat",
23
+ "build:web": "ray build ./example --target=web",
24
+ "build:native": "ray build ./example --target=native",
25
+ "start:native": "ray start ./example -t native --verbose",
26
+ "start:tuya": "ray start -t tuya ./example",
27
+ "start:wechat": "ray start ./example -t wechat --verbose",
28
+ "start:web": "ray start ./example -t web",
29
+ "prepublishOnly": "yarn build",
30
+ "release-it": "standard-version",
31
+ "test": "jest ./src",
32
+ "test:watch": "jest ./src --watch",
33
+ "test:coverage": "jest ./src --coverage"
34
+ },
35
+ "peerDependencies": {
36
+ "@ray-js/ray": "^1.6.13"
37
+ },
38
+ "dependencies": {},
39
+ "devDependencies": {
40
+ "@babel/core": "^7.0.0",
41
+ "@commitlint/cli": "^7.2.1",
42
+ "@commitlint/config-conventional": "^9.0.1",
43
+ "@ray-js/cli": "^1.4.9",
44
+ "@ray-js/panel-sdk": "^1.13.6-beta.2",
45
+ "@ray-js/ray": "^1.6.13",
46
+ "@testing-library/dom": "^10.0.0",
47
+ "@testing-library/react": "^16.3.0",
48
+ "@testing-library/react-hooks": "^8.0.1",
49
+ "@types/jest": "^29.5.14",
50
+ "@types/lodash-es": "^4.17.12",
51
+ "core-js": "^3.19.1",
52
+ "eslint-config-tuya-panel": "^0.4.2",
53
+ "husky": "^1.2.0",
54
+ "jest": "^29.7.0",
55
+ "jest-environment-jsdom": "^29.7.0",
56
+ "lint-staged": "^10.2.11",
57
+ "lodash-es": "^4.17.21",
58
+ "patch-package": "^8.0.0",
59
+ "react": "^17.0.2",
60
+ "react-dom": "^17.0.2",
61
+ "standard-version": "9.3.2",
62
+ "ts-jest": "^29.1.2",
63
+ "typescript": "^4.3.0"
64
+ },
65
+ "resolutions": {
66
+ "@ray-js/builder-mp": "1.4.15"
67
+ },
68
+ "lint-staged": {
69
+ "*.{ts,tsx,js,jsx}": [
70
+ "eslint --fix",
71
+ "git add"
72
+ ],
73
+ "*.{json,md,yml,yaml}": [
74
+ "prettier --write",
75
+ "git add"
76
+ ]
77
+ }
78
+ }