11const fs = require ( 'fs' ) ;
22const path = require ( 'path' ) ;
3- const moment = require ( 'moment-timezone' ) ;
4- const Hashids = require ( 'hashids' ) ;
5- const hashids = new Hashids ( ) ;
6-
7- class frame {
8- /**
9- * constructor.
10- * @param config
11- * @param id
12- * @param type
13- */
14- constructor ( config , id , type ) {
15- this . config = config ;
16- this . project = config . get ( 'project' ) ;
17- this . resource = { id, type} ;
18-
19- if ( typeof id === 'string' || id instanceof String )
20- this . resource . new = true ;
21-
22- this . id = frame . generateId ( ) ;
23- this . _start = false ;
24- this . _stop = false ;
25- this . timezone = config . get ( 'timezone' ) ;
26- this . notes = [ ] ;
27- }
28-
29- static fromJson ( config , json ) {
30- let frame = new this ( config , json . resource . id , json . resource . type ) ;
31- frame . project = json . project ;
32- frame . id = json . id ;
33- frame . _start = json . start ;
34- frame . _stop = json . stop ;
35- frame . notes = json . notes ;
36- frame . timezone = json . timezone ;
37- frame . validate ( ) ;
38-
39- return frame ;
40- }
3+ const BaseFrame = require ( './baseFrame.js' ) ;
414
5+ class frame extends BaseFrame {
426 static fromFile ( config , file ) {
437 return frame . fromJson ( config , JSON . parse ( fs . readFileSync ( file ) ) ) ;
448 }
@@ -57,25 +21,6 @@ class frame {
5721 return this ;
5822 }
5923
60- validate ( ) {
61- moment . suppressDeprecationWarnings = true ;
62-
63- if ( ! moment ( this . _start ) . isValid ( ) )
64- throw `Error: Start date is not in a valid ISO date format!` ;
65-
66- if ( this . _stop && ! moment ( this . _stop ) . isValid ( ) )
67- throw `Error: Stop date is not in a valid ISO date format!` ;
68-
69- moment . suppressDeprecationWarnings = false ;
70- }
71-
72- _getCurrentDate ( ) {
73- if ( this . timezone )
74- return moment ( ) . tz ( this . timezone ) . format ( ) ;
75-
76- return moment ( ) ;
77- }
78-
7924 /**
8025 * assert file exists
8126 */
@@ -102,30 +47,6 @@ class frame {
10247 get file ( ) {
10348 return path . join ( this . config . frameDir , this . id + '.json' ) ;
10449 }
105-
106- get duration ( ) {
107- return moment ( this . stop ) . diff ( this . start ) / 1000 ;
108- }
109-
110- get date ( ) {
111- return this . start ;
112- }
113-
114- get start ( ) {
115- return this . timezone ? moment ( this . _start ) . tz ( this . timezone ) : moment ( this . _start ) ;
116- }
117-
118- get stop ( ) {
119- return this . timezone ? moment ( this . _stop ) . tz ( this . timezone ) : ( this . _stop ? moment ( this . _stop ) : false ) ;
120- }
121-
122- /**
123- * generate a unique id
124- * @returns {number }
125- */
126- static generateId ( ) {
127- return hashids . encode ( new Date ( ) . getTime ( ) ) ;
128- }
12950}
13051
131- module . exports = frame ;
52+ module . exports = frame ;
0 commit comments