comparison lib/js/urweb.js @ 1599:252e05bf199d

Regenerate proper Autotools files; fix JS stringToTime and add stringToTime_error
author Adam Chlipala <adam@chlipala.net>
date Fri, 18 Nov 2011 17:17:22 -0500
parents e283ca05c829
children c6cc104a47ac
comparison
equal deleted inserted replaced
1598:cdca9691434a 1599:252e05bf199d
110 function round(n) { 110 function round(n) {
111 return Math.round(n); 111 return Math.round(n);
112 } 112 }
113 113
114 114
115 // Time 115 // Time, represented as counts of microseconds since the epoch
116 116
117 function showTime(tm) { 117 function showTime(tm) {
118 var newDate = new Date(); 118 var newDate = new Date();
119 newDate.setTime(tm / 1000); 119 newDate.setTime(tm / 1000);
120 return newDate.toUTCString(); 120 var r = newDate.toUTCString();
121 return r;
121 } 122 }
122 123
123 function now() { 124 function now() {
124 return (new Date()).getTime() * 1000; 125 return (new Date()).getTime() * 1000;
125 } 126 }
134 135
135 function addSeconds(tm, n) { 136 function addSeconds(tm, n) {
136 return tm + n * 1000000; 137 return tm + n * 1000000;
137 } 138 }
138 139
139 function stringToTime(string){ 140 function stringToTime_error(string) {
140 return Date.parse(string) // returns milliseconds and we need microseconds 141 var t = Date.parse(string);
141 * 1000; 142 if (isNaN(t))
143 onFail("Invalid date string: " + string);
144 else
145 return t * 1000;
146 }
147
148 function stringToTime(string) {
149 try {
150 var t = Date.parse(string);
151 if (isNaN(t))
152 return null;
153 else
154 return t * 1000;
155 } catch (e) {
156 return null;
157 }
142 } 158 }
143 159
144 160
145 // Error handling 161 // Error handling
146 162