File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } current
3
+ * @param {string } correct
4
+ * @return {number }
5
+ */
6
+ var convertTime = function ( current , correct ) {
7
+ const s = current . split ( ':' ) . map ( e => + e )
8
+ const t = correct . split ( ':' ) . map ( e => + e )
9
+ let res = 0
10
+ // hour
11
+ if ( s [ 0 ] < t [ 0 ] ) res += t [ 0 ] - s [ 0 ]
12
+ else if ( s [ 0 ] > t [ 0 ] ) res += ( 24 - ( s [ 0 ] - t [ 0 ] ) )
13
+
14
+ // min
15
+ let delta = t [ 1 ] - s [ 1 ]
16
+ if ( delta > 0 ) {
17
+ if ( delta >= 15 ) {
18
+ res += ~ ~ ( delta / 15 )
19
+ delta %= 15
20
+ }
21
+ if ( delta >= 5 ) {
22
+ res += ~ ~ ( delta / 5 )
23
+ delta %= 5
24
+ }
25
+ res += delta
26
+ } else if ( delta < 0 ) {
27
+ res --
28
+ delta += 60
29
+ if ( delta >= 15 ) {
30
+ res += ~ ~ ( delta / 15 )
31
+ delta %= 15
32
+ }
33
+ if ( delta >= 5 ) {
34
+ res += ~ ~ ( delta / 5 )
35
+ delta %= 5
36
+ }
37
+ res += delta
38
+ }
39
+
40
+ return res
41
+ } ;
You can’t perform that action at this time.
0 commit comments