MCPcopy Create free account
hub / github.com/QLHazyCoder/FlowPilot / parseMailItemTimestamp

Function parseMailItemTimestamp

content/mail-2925.js:206–268  ·  view source on GitHub ↗
(item)

Source from the content-addressed store, hash-verified

204}
205
206function parseMailItemTimestamp(item) {
207 const timeText = getMailItemTimeText(item);
208 if (!timeText) return null;
209
210 const now = new Date();
211 const date = new Date(now);
212 let match = null;
213
214 if (/刚刚/.test(timeText)) {
215 return now.getTime();
216 }
217
218 match = timeText.match(/(\d+)\s*分(?:钟)?前/);
219 if (match) {
220 return now.getTime() - Number(match[1]) * 60 * 1000;
221 }
222
223 match = timeText.match(/(\d+)\s*秒前/);
224 if (match) {
225 return now.getTime() - Number(match[1]) * 1000;
226 }
227
228 match = timeText.match(/^(\d{1,2}):(\d{2})$/);
229 if (match) {
230 date.setHours(Number(match[1]), Number(match[2]), 0, 0);
231 return date.getTime();
232 }
233
234 match = timeText.match(/今天\s*(\d{1,2}):(\d{2})/);
235 if (match) {
236 date.setHours(Number(match[1]), Number(match[2]), 0, 0);
237 return date.getTime();
238 }
239
240 match = timeText.match(/昨天\s*(\d{1,2}):(\d{2})/);
241 if (match) {
242 date.setDate(date.getDate() - 1);
243 date.setHours(Number(match[1]), Number(match[2]), 0, 0);
244 return date.getTime();
245 }
246
247 match = timeText.match(/(\d{1,2})-(\d{1,2})\s*(\d{1,2}):(\d{2})/);
248 if (match) {
249 date.setMonth(Number(match[1]) - 1, Number(match[2]));
250 date.setHours(Number(match[3]), Number(match[4]), 0, 0);
251 return date.getTime();
252 }
253
254 match = timeText.match(/(\d{4})-(\d{1,2})-(\d{1,2})\s*(\d{1,2}):(\d{2})/);
255 if (match) {
256 return new Date(
257 Number(match[1]),
258 Number(match[2]) - 1,
259 Number(match[3]),
260 Number(match[4]),
261 Number(match[5]),
262 0,
263 0

Callers 1

handlePollEmailFunction · 0.85

Calls 1

getMailItemTimeTextFunction · 0.85

Tested by

no test coverage detected