mm_expand 1.6.6 → 1.6.7

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 (3) hide show
  1. package/index.js +24 -15
  2. package/package.json +1 -1
  3. package/test.js +46 -18
package/index.js CHANGED
@@ -539,7 +539,8 @@ if (typeof($) === "undefined") {
539
539
  // 当前系统路径使用的斜杠
540
540
  slash: slash,
541
541
  // 系统跟目录
542
- rootPath, rootPath,
542
+ rootPath,
543
+ rootPath,
543
544
  // 运行根目录
544
545
  runPath: process.cwd() + slash,
545
546
  // 延迟
@@ -684,18 +685,22 @@ if (typeof($) === "undefined") {
684
685
  * @return {String} 时间格式字符串
685
686
  */
686
687
  Date.prototype.toStr = function(format) {
688
+ var t = this;
689
+ if (format.endsWith('Z')) {
690
+ t = t.addSeconds(-28800);
691
+ }
687
692
  var o = {
688
- "M+": this.getMonth() + 1,
689
- "d+": this.getDate(),
690
- "h+": this.getHours(),
691
- "m+": this.getMinutes(),
692
- "s+": this.getSeconds(),
693
- "q+": Math.floor((this.getMonth() + 3) / 3),
694
- "S": this.getMilliseconds()
693
+ "M+": t.getMonth() + 1,
694
+ "d+": t.getDate(),
695
+ "h+": t.getHours(),
696
+ "m+": t.getMinutes(),
697
+ "s+": t.getSeconds(),
698
+ "q+": Math.floor((t.getMonth() + 3) / 3),
699
+ "S": t.getMilliseconds()
695
700
  };
696
701
  if (/(y+)/.test(format)) {
697
702
  var x = RegExp.$1;
698
- format = format.replace(x, (this.getFullYear() + "").substr(4 - x.length));
703
+ format = format.replace(x, (t.getFullYear() + "").substr(4 - x.length));
699
704
  }
700
705
  for (var k in o) {
701
706
  if (new RegExp("(" + k + ")").test(format)) {
@@ -1038,17 +1043,21 @@ if (typeof($) === "undefined") {
1038
1043
  }
1039
1044
  };
1040
1045
  /**
1041
- * @description 转为时间对象
1042
- * @return {Date} 时间对象
1046
+ * @description 转为时间对象
1047
+ * @return {Date} 返回时间对象类型
1043
1048
  */
1044
1049
  String.prototype.toTime = function() {
1045
1050
  var str = this;
1046
1051
  var time;
1047
1052
  if (str.indexOf('T') !== -1) {
1048
- str = this.replace('T', ' ').replace('Z', '').replaceAll('-', '/');
1049
- time = new Date(str).addSeconds(28800);
1050
- }
1051
- else {
1053
+ str = this.replace('T', ' ').replaceAll('-', '/');
1054
+ if (str.indexOf('Z') !== -1) {
1055
+ str = str.replace('Z', '');
1056
+ time = (new Date(str)).addSeconds(28800);
1057
+ } else {
1058
+ time = new Date(str);
1059
+ }
1060
+ } else {
1052
1061
  str = this.replaceAll('-', '/');
1053
1062
  time = new Date(str);
1054
1063
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_expand",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "这是超级美眉原型函数拓展模块,更有利于对string、array、object的操作,避免出错,简化业务逻辑。",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -1,24 +1,52 @@
1
1
  require('./index.js');
2
2
 
3
+
4
+ var now = new Date();
5
+ var str = now;
6
+ console.log("时间", str);
7
+ console.log("时间", str.toString());
8
+ console.log("当前", new Date(str.toString()).toStr("yyyy-MM-dd hh:mm:ss"));
9
+
10
+ var time = now.toStr('yyyy-MM-dd hh:mm:ss');
11
+ console.log("当前", time);
12
+ console.log("时间", time.toTime().toStr("yyyy-MM-dd hh:mm:ss"));
13
+ console.log("当前", new Date(time).toStr("yyyy-MM-dd hh:mm:ss"));
14
+
15
+ var time = now.toStr("yyyy-MM-ddThh:mm");
16
+ console.log("当前", time);
17
+ console.log("时间", time.toTime().toStr("yyyy-MM-dd hh:mm:ss"));
18
+
19
+
20
+ var time = now.toStr("yyyy-MM-ddThh:mm:ss.000Z");
21
+ console.log("当前", time);
22
+ console.log("时间", time.toTime().addSeconds(28800).toStr("yyyy-MM-dd hh:mm:ss"));
23
+
24
+ var json = {
25
+ now
26
+ };
27
+ var jtime = JSON.stringify(json);
28
+ console.log("时间", jtime);
29
+ console.log("时间", (jtime.toJson()).now.toTime().toStr("yyyy-MM-dd hh:mm:ss"));
30
+
3
31
  // console.log($.rootPath);
4
- console.log("./fast/log".fullname(__dirname));
5
- console.log("./fast/log".fullname());
6
- console.log("./fast/log/".fullname());
7
- console.log("fast/log".fullname(__dirname));
8
- console.log("fast/log".fullname());
9
- console.log("fast/log/".fullname());
10
- console.log("../fast/log".fullname(__dirname));
11
- console.log("../fast/log".fullname());
12
- console.log("/fast/log".fullname(__dirname));
13
- console.log("/fast/log".fullname());
14
- console.log("/fast/log/".fullname());
15
- console.log("/fast/log.lgo".fullname());
16
- console.log("/fast/log.lgo\\".fullname());
17
- console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log\\".fullname(__dirname));
18
- console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log\\".fullname());
19
- console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log".fullname());
20
-
21
- console.log("/fast/log.lgo\\log".fullname());
32
+ // console.log("./fast/log".fullname(__dirname));
33
+ // console.log("./fast/log".fullname());
34
+ // console.log("./fast/log/".fullname());
35
+ // console.log("fast/log".fullname(__dirname));
36
+ // console.log("fast/log".fullname());
37
+ // console.log("fast/log/".fullname());
38
+ // console.log("../fast/log".fullname(__dirname));
39
+ // console.log("../fast/log".fullname());
40
+ // console.log("/fast/log".fullname(__dirname));
41
+ // console.log("/fast/log".fullname());
42
+ // console.log("/fast/log/".fullname());
43
+ // console.log("/fast/log.lgo".fullname());
44
+ // console.log("/fast/log.lgo\\".fullname());
45
+ // console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log\\".fullname(__dirname));
46
+ // console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log\\".fullname());
47
+ // console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log".fullname());
48
+
49
+ // console.log("/fast/log.lgo\\log".fullname());
22
50
  // var arr1 = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
23
51
 
24
52
  // var arr1 = [{