trim: function() {\r
return this.string.replace(/[\s\n]+/g, "");\r
},\r
- offset: function() {\r
- return parseFloat(this.trim().match(/[\+\-]?\d+$/) || 0);\r
+ offset: function(str) {\r
+ var plusminus = str.charAt(0),\r
+ s = ms() + sec() + min() + h();\r
+ if (plusminus === "-") {\r
+ s *= -1;\r
+ }\r
+ plusminus = ms = min = h = void 0;\r
+ return s;\r
+ \r
+ function ms() {\r
+ var deg = str.match(/\d+ms$/) || "0";\r
+ return ( parseFloat(deg) );\r
+ };\r
+ function sec() {\r
+ var deg = str.match(/:\d+$/) || "0",\r
+ de = str.match(/\d+s$/) || "0",\r
+ d = str.match(/\d+$/) || "0";\r
+ return ( 1000*( parseFloat(deg) || parseFloat(de) || parseFloat(d) ) );\r
+ };\r
+ function min() {\r
+ var deg = str.match(/:\d\d:/) || "0",\r
+ de = str.match(/\d+min$/) || "0",\r
+ d = str.match(/\d\d:[^:]+$/) || "0";\r
+ return ( 60000*( parseFloat(deg) || parseFloat(de) || parseFloat(d) ) );\r
+ };\r
+ function h() {\r
+ var deg = str.match(/\d+:\d\d:/) || "0",\r
+ de = str.match(/\d+h$/) || "0";\r
+ return ( 3600000*( parseFloat(deg) || parseFloat(de) ) );\r
+ };\r
},\r
event: function() {\r
}\r
expect(begin.trim()).toBe("");\r
begin.string = " ";\r
expect(begin.trim()).toBe("");\r
- expect(begin.offset()).toEqual(0);\r
- begin.string = "+20ms";\r
- expect(begin.offset()).toEqual(20);\r
+ expect(begin.offset(begin.trim())).toEqual(0);\r
+ begin.string = "+0ms";\r
+ expect(begin.offset(begin.trim())).toEqual(0);\r
+ begin.string = "-0ms";\r
+ expect(begin.offset(begin.trim())).toEqual(0);\r
+ begin.string = "1ms";\r
+ expect(begin.offset(begin.trim())).toEqual(1);\r
+ begin.string = "-1ms";\r
+ expect(begin.offset(begin.trim())).toEqual(-1);\r
} );\r
/*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
it("should be this for the value (the valid partion)", function() {\r
begin.string = " h o g e ";\r
expect(begin.trim()).toBe("hoge");\r
\r
- expect(begin.offset()).toEqual(0);\r
+ expect(begin.offset(begin.trim())).toEqual(0);\r
} );\r
/*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
it("should be this for the value (the invalid partion)", function() {\r