Skip to content

Commit b02e1d3

Browse files
committed
[refactor] switch to moment js
1 parent da84b2e commit b02e1d3

File tree

6 files changed

+106
-137
lines changed

6 files changed

+106
-137
lines changed

‎gulpfile.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const filename ={
3232

3333
constjsDependencies=[
3434
path.nodeModules+'/html5sortable/dist/html5sortable.min.js',
35-
path.nodeModules+'/invert-color/lib/invert.min.js'
35+
path.nodeModules+'/invert-color/lib/invert.min.js',
36+
path.nodeModules+'/moment/min/moment.min.js'
3637
]
3738

3839
constcssFiles=[

‎package-lock.json‎

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"gulp-watch": "^5.0.1",
5151
"html5sortable": "^0.9.16",
5252
"invert-color": "^2.0.0",
53-
"web-ext": "^3.1.1"
53+
"web-ext": "^3.1.1",
54+
"moment": "^2.24.0"
5455
}
5556
}

‎src/index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ <h1 class="menu-item-header-text">nightTab</h1>
13381338
<!-- vendor -->
13391339
<scriptsrc="../node_modules/html5sortable/dist/html5sortable.min.js"></script>
13401340
<scriptsrc="../node_modules/invert-color/lib/invert.min.js"></script>
1341+
<scriptsrc="../node_modules/moment/min/moment.min.js"></script>
13411342
<!-- nightTab -->
13421343
<scriptsrc="js/helper.js"></script>
13431344
<scriptsrc="js/data.js"></script>

‎src/js/clock.js‎

Lines changed: 54 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
varclock=(function(){
22

3-
var_makeTimeObject=function(){
4-
vartime=helper.getDateTime();
5-
time.meridiem="AM";
6-
if(state.get().header.clock.hour24.show){
7-
if(time.hours<10){
8-
time.hours="0"+time.hours;
9-
};
10-
}else{
11-
if(time.hours>12){
12-
time.meridiem="PM";
13-
time.hours=time.hours-12;
14-
};
15-
if(time.hours==0){
16-
time.hours=12;
17-
};
18-
};
19-
if(time.minutes<10){
20-
time.minutes="0"+time.minutes;
21-
};
22-
if(time.seconds<10){
23-
time.seconds="0"+time.seconds;
24-
};
25-
returntime;
26-
};
27-
283
varbind={};
294

305
bind.tick=function(){
@@ -45,77 +20,76 @@ var clock = (function(){
4520

4621
render.all=function(){
4722
if(state.get().header.clock.seconds.show||state.get().header.clock.minutes.show||state.get().header.clock.hours.show){
48-
varclock=helper.e(".clock");
49-
vartimeObject=_makeTimeObject();
23+
vartimeDateNow=moment();
24+
vartimeStrings={
25+
hours: null,
26+
minutes: null,
27+
seconds: null,
28+
meridiem: null
29+
};
5030
varaction={
5131
hours: {
52-
word: function(value){
53-
if(state.get().header.clock.hour24.show&&value<10){
54-
return"Zero "+helper.toWords(value);
55-
}else{
56-
returnhelper.toWords(value);
32+
word: function(){
33+
timeStrings.hours=timeDateNow.hours();
34+
if(!state.get().header.clock.hour24.show&&timeDateNow.hours()>12){
35+
timeStrings.hours=timeStrings.hours-12;
36+
};
37+
timeStrings.hours=helper.toWords(timeDateNow.hours());
38+
if(state.get().header.clock.hour24.show&&timeDateNow.hours()>0&&timeDateNow.hours()<10){
39+
timeStrings.hours="Zero "+timeStrings.hours;
5740
};
5841
},
59-
number: function(value){
60-
returnvalue;
42+
number: function(){
43+
timeStrings.hours=timeDateNow.hours();
44+
if(!state.get().header.clock.hour24.show&&timeDateNow.hours()>12){
45+
timeStrings.hours=timeStrings.hours-12;
46+
};
47+
if(state.get().header.clock.hour24.show&&timeDateNow.hours()<10){
48+
timeStrings.hours="0"+timeStrings.hours;
49+
};
6150
}
6251
},
6352
minutes: {
64-
word: function(value){
65-
if(value<10){
66-
return"Zero "+helper.toWords(value);
67-
}else{
68-
returnhelper.toWords(value);
53+
word: function(){
54+
timeStrings.minutes=helper.toWords(timeDateNow.minutes());
55+
if(timeDateNow.minutes()>0&&timeDateNow.minutes()<10){
56+
timeStrings.minutes="Zero "+timeStrings.minutes;
6957
};
7058
},
71-
number: function(value){
72-
returnvalue;
59+
number: function(){
60+
timeStrings.minutes=timeDateNow.minutes();
61+
if(timeDateNow.minutes()<10){
62+
timeStrings.minutes="0"+timeStrings.minutes;
63+
};
7364
}
7465
},
7566
seconds: {
76-
word: function(value){
77-
returnhelper.toWords(value);
67+
word: function(){
68+
timeStrings.seconds=helper.toWords(timeDateNow.seconds());
69+
if(timeDateNow.seconds()>0&&timeDateNow.seconds()<10){
70+
timeStrings.seconds="Zero "+timeStrings.seconds;
71+
};
7872
},
79-
number: function(value){
80-
returnvalue;
73+
number: function(){
74+
timeStrings.seconds=timeDateNow.seconds();
75+
if(timeDateNow.seconds()<10){
76+
timeStrings.seconds="0"+timeStrings.seconds;
77+
};
8178
}
79+
},
80+
meridiem: function(){
81+
timeStrings.meridiem=timeDateNow.format("A");
8282
}
8383
};
84-
timeObject.hours=action.hours[state.get().header.clock.hours.display](timeObject.hours);
85-
timeObject.minutes=action.minutes[state.get().header.clock.minutes.display](timeObject.minutes);
86-
timeObject.seconds=action.seconds[state.get().header.clock.seconds.display](timeObject.seconds);
87-
varelementHours=helper.makeNode({
88-
tag: "span",
89-
text: timeObject.hours,
90-
attr: [{
91-
key: "class",
92-
value: "clock-item clock-hours"
93-
}]
94-
});
95-
varelementMinutes=helper.makeNode({
96-
tag: "span",
97-
text: timeObject.minutes,
98-
attr: [{
99-
key: "class",
100-
value: "clock-item clock-minutes"
101-
}]
102-
});
103-
varelementSeconds=helper.makeNode({
104-
tag: "span",
105-
text: timeObject.seconds,
106-
attr: [{
107-
key: "class",
108-
value: "clock-item clock-seconds"
109-
}]
110-
});
111-
varelementMeridiem=helper.makeNode({
112-
tag: "span",
113-
text: timeObject.meridiem,
114-
attr: [{
115-
key: "class",
116-
value: "clock-item clock-meridiem"
117-
}]
118-
});
84+
action.hours[state.get().header.clock.hours.display]();
85+
action.minutes[state.get().header.clock.minutes.display]();
86+
action.seconds[state.get().header.clock.seconds.display]();
87+
action.meridiem();
88+
varclock=helper.e(".clock");
89+
varelementHours=helper.node("span:"+timeStrings.hours+"|class:clock-item clock-hours");
90+
varelementMinutes=helper.node("span:"+timeStrings.minutes+"|class:clock-item clock-minutes");
91+
varelementSeconds=helper.node("span:"+timeStrings.seconds+"|class:clock-item clock-seconds");
92+
varelementMeridiem=helper.node("span:"+timeStrings.meridiem+"|class:clock-item clock-meridiem");
11993
if(state.get().header.clock.hours.show){
12094
clock.appendChild(elementHours);
12195
};

‎src/js/date.js‎

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
vardate=(function(){
22

3-
var_makeTimeObject=function(){
4-
returnhelper.getDateTime();
5-
};
6-
7-
var_month=function(index){
8-
varall=["January","February","March","April","May","June","July","August","September","October","November","December"];
9-
returnall[index];
10-
};
11-
12-
var_day=function(index){
13-
varall=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
14-
returnall[index];
15-
};
16-
173
varbind={};
184

195
bind.tick=function(){
@@ -34,75 +20,82 @@ var date = (function(){
3420

3521
render.all=function(){
3622
if(state.get().header.date.date.show||state.get().header.date.day.show||state.get().header.date.month.show||state.get().header.date.year.show){
37-
vardate=helper.e(".date");
38-
vardateObject=_makeTimeObject();
23+
vartimeDateNow=moment();
24+
vardateStrings={
25+
day: null,
26+
date: null,
27+
month: null,
28+
year: null
29+
};
3930
varwordOrNumber={
4031
day: {
41-
word: function(value){
42-
return_day(value);
32+
word: function(){
33+
dateStrings.day=timeDateNow.format("dddd");
34+
if(state.get().header.date.day.length=="short"){
35+
dateStrings.day=dateStrings.day.substring(0,3);
36+
console.log(dateStrings.day);
37+
};
4338
},
44-
number: function(value){
39+
number: function(){
40+
dateStrings.day=timeDateNow.day();
4541
if(state.get().header.date.day.weekStart=="monday"){
46-
if(value==0){
47-
value=7;
42+
if(dateStrings.day==0){
43+
dateStrings.day=7;
4844
};
4945
}elseif(state.get().header.date.day.weekStart=="sunday"){
50-
value=value+1;
46+
dateStrings.day=dateStrings.day+1;
5147
};
52-
returnvalue;
5348
}
5449
},
5550
date: {
56-
word: function(value){
51+
word: function(){
5752
if(state.get().header.date.date.ordinal){
58-
returnhelper.ordinalWords(helper.toWords(value));
53+
dateStrings.date=helper.ordinalWords(helper.toWords(timeDateNow.date()));
5954
}else{
60-
returnhelper.toWords(value);
55+
dateStrings.date=helper.toWords(timeDateNow.date());
6156
};
6257
},
63-
number: function(value){
58+
number: function(){
6459
if(state.get().header.date.date.ordinal){
65-
returnhelper.ordinalNumber(value);
60+
dateStrings.date=timeDateNow.format("Do");
6661
}else{
67-
returnvalue;
62+
dateStrings.date=timeDateNow.format("DD");
6863
};
6964
}
7065
},
7166
month: {
72-
word: function(value){
73-
return_month(value);
67+
word: function(){
68+
dateStrings.month=timeDateNow.format("MMMM");
69+
if(state.get().header.date.month.length=="short"){
70+
dateStrings.month=dateStrings.month.substring(0,3);
71+
};
7472
},
75-
number: function(value){
73+
number: function(){
7674
if(state.get().header.date.month.ordinal){
77-
returnhelper.ordinalNumber(value+1);
75+
dateStrings.month=helper.ordinalNumber(timeDateNow.month()+1);
7876
}else{
79-
returnvalue+1;
77+
dateStrings.month=timeDateNow.month()+1;
8078
};
8179
}
8280
},
8381
year: {
84-
word: function(value){
85-
returnhelper.toWords(value);
82+
word: function(){
83+
dateStrings.year=helper.toWords(timeDateNow.format("YYYY"));
8684
},
87-
number: function(value){
88-
returnvalue;
85+
number: function(){
86+
dateStrings.year=timeDateNow.format("YYYY");
8987
}
9088
}
9189
};
92-
dateObject.day=wordOrNumber.day[state.get().header.date.day.display](dateObject.day);
93-
dateObject.date=wordOrNumber.date[state.get().header.date.date.display](dateObject.date);
94-
dateObject.month=wordOrNumber.month[state.get().header.date.month.display](dateObject.month);
95-
dateObject.year=wordOrNumber.year[state.get().header.date.year.display](dateObject.year);
96-
if(state.get().header.date.day.display=="word"&&state.get().header.date.day.length=="short"){
97-
dateObject.day=dateObject.day.substring(0,3);
98-
};
99-
if(state.get().header.date.month.display=="word"&&state.get().header.date.month.length=="short"){
100-
dateObject.month=dateObject.month.substring(0,3);
101-
};
102-
varelementDay=helper.node("span:"+dateObject.day+"|class:date-item date-day");
103-
varelementDate=helper.node("span:"+dateObject.date+"|class:date-item date-date");
104-
varelementMonth=helper.node("span:"+dateObject.month+"|class:date-item date-month");
105-
varelementyear=helper.node("span:"+dateObject.year+"|class:date-item date-year");
90+
wordOrNumber.day[state.get().header.date.day.display]();
91+
wordOrNumber.date[state.get().header.date.date.display]();
92+
wordOrNumber.month[state.get().header.date.month.display]();
93+
wordOrNumber.year[state.get().header.date.year.display]();
94+
varelementDay=helper.node("span:"+dateStrings.day+"|class:date-item date-day");
95+
varelementDate=helper.node("span:"+dateStrings.date+"|class:date-item date-date");
96+
varelementMonth=helper.node("span:"+dateStrings.month+"|class:date-item date-month");
97+
varelementYear=helper.node("span:"+dateStrings.year+"|class:date-item date-year");
98+
vardate=helper.e(".date");
10699
if(state.get().header.date.day.show){
107100
date.appendChild(elementDay);
108101
};
@@ -131,7 +124,7 @@ var date = (function(){
131124
};
132125
};
133126
if(state.get().header.date.year.show){
134-
date.appendChild(elementyear);
127+
date.appendChild(elementYear);
135128
};
136129
if(state.get().header.date.separator.show){
137130
varseparatorCharacter="/";

0 commit comments

Comments
(0)