offset: function(str) {\r
str = str || "0";\r
var plusminus = str.charAt(0),\r
- s = ms() + sec() + min() + h();\r
+ /*parseFloatのエイリアス*/\r
+ _float = parseFloat,\r
+ s = _float( str.match(/[\d.]+ms$/) || "0") + sec() + min() + h();\r
if (plusminus === "-") {\r
s *= -1;\r
}\r
- plusminus = ms = min = h = void 0;\r
+ plusminus = _float = sec = min = h = void 0;\r
return s;\r
\r
- function ms() {\r
- return parseFloat( str.match(/[\d.]+ms$/) || "0");\r
- };\r
function sec() {\r
- var deg = str.match(/[\d.]+s$/) || "0",\r
- de = str.match(/[\d.]+$/) || "0";\r
- return ( 1000*( parseFloat(deg) || parseFloat(de) ) );\r
+ return ( 1000*( _float(str.match(/[\d.]+s$/) || "0") || _float(str.match(/[\d.]+$/) || "0") ) );\r
};\r
function min() {\r
- var deg = str.match(/[\d.]+min$/) || "0",\r
- de = str.match(/\d\d:[^:]+$/) || "0";\r
- return ( 60000*( parseFloat(deg) || parseFloat(de) ) );\r
+ return ( 60000*( _float(str.match(/[\d.]+min$/) || "0") || _float(str.match(/\d\d:[^:]+$/) || "0") ) );\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
+ return ( 3600000*( _float(str.match(/\d+:\d\d:/) || "0") || _float(str.match(/[\d.]+h$/) || "0") ) );\r
};\r
},\r
event: function() {\r
expect(begin.offset("-00:00:0.0")).toEqual(0);\r
expect(begin.offset("00:1")).toEqual(1000);\r
expect(begin.offset("-00:1")).toEqual(-1000);\r
+ expect(begin.offset("00:00:1")).toEqual(1000);\r
+ expect(begin.offset("-00:00:1")).toEqual(-1000);\r
\r
expect(begin.offset()).toEqual(0);\r
} );\r
expect(begin.offset("-0.20h")).toEqual(-0.20 * 3600000);\r
expect(begin.offset(".20h")).toEqual(0.20 * 3600000);\r
\r
+ expect(begin.offset("01:0")).toEqual(60000);\r
+ expect(begin.offset("-01:0")).toEqual(-60000);\r
+ expect(begin.offset("00:00:1")).toEqual(1000);\r
+ expect(begin.offset("-00:00:1")).toEqual(-1000);\r
+ expect(begin.offset("00:01:0")).toEqual(60000);\r
+ expect(begin.offset("-00:01:0")).toEqual(-60000);\r
+ expect(begin.offset("01:00:0")).toEqual(3600000);\r
+ expect(begin.offset("-01:00:0")).toEqual(-3600000);\r
expect(begin.offset("00:10")).toEqual(10000);\r
expect(begin.offset("00:0.01")).toEqual(10);\r
expect(begin.offset("01:0.01")).toEqual(60010);\r
expect(begin.offset("-00:0.01")).toEqual(-10);\r
expect(begin.offset("-01:0.01")).toEqual(-60010);\r
expect(begin.offset("-10:0")).toEqual(-600000);\r
- expect(begin.offset("00:00:1")).toEqual(1000);\r
expect(begin.offset("00:00:20")).toEqual(20000);\r
expect(begin.offset("00:11:20")).toEqual(11*60*1000 + 20000);\r
expect(begin.offset("12:11:20")).toEqual(12*60*60*1000 + 11*60*1000 + 20000);\r
expect(begin.offset("-::0")).toEqual(0);\r
} );\r
} );\r
-\r
describe("An event method in $begin object", function() {\r
/*境界条件を調べておく (limit value analysis)*/\r
it("should be this for the value (limit value analysis)", function() {\r