From da85b09c600ddcf4e5c8cad66012fa29a8252b39 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 12 六月 2024 23:40:33 +0800
Subject: [PATCH] 岗位资源更新

---
 src/utils/is.ts |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/utils/is.ts b/src/utils/is.ts
index ae7609c..9f47d93 100644
--- a/src/utils/is.ts
+++ b/src/utils/is.ts
@@ -100,3 +100,38 @@
   const reg = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/;
   return reg.test(path);
 }
+
+export function isTime(value: any): value is Date {
+  return value instanceof Date && !isNaN(value.getTime());
+}
+
+export function isTimeViaConstructor(value: any): boolean {
+  return value instanceof Date || value.constructor === Date;
+}
+
+export function isTimeViaRegExp(value: any): boolean {
+  return /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(value.toString());
+}
+
+export function isTimeType(value: string): boolean {
+  return !isNaN(Date.parse(value));
+}
+
+export function isValidJSON(text: string): boolean {
+  try {
+      JSON.parse(text);
+      return true;
+  } catch (error) {
+      return false;
+  }
+}
+
+// // 绀轰緥
+// const time1 = new Date();
+// console.log(isTime(time1)); // true
+
+// const time2 = '2023-04-01T12:00:00Z';
+// console.log(isTimeViaRegExp(time2)); // true
+
+// const notTime = 'hello world';
+// console.log(isTime(notTime)); // false

--
Gitblit v1.9.3