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

Function parseGmailTimestampText

content/gmail-mail.js:116–166  ·  view source on GitHub ↗
(rawText)

Source from the content-addressed store, hash-verified

114};
115
116function parseGmailTimestampText(rawText) {
117 const text = normalizeText(rawText);
118 if (!text) return null;
119
120 const parsedNative = Date.parse(text);
121 if (Number.isFinite(parsedNative)) {
122 return parsedNative;
123 }
124
125 let match = text.match(/(\d{4})[年/-](\d{1,2})[月/-](\d{1,2})日?\s+(\d{1,2}):(\d{2})(?:\s*([AP]M))?/i);
126 if (match) {
127 const [, year, month, day, hourText, minute, meridiem] = match;
128 let hour = Number(hourText);
129 if (/pm/i.test(meridiem) && hour < 12) hour += 12;
130 if (/am/i.test(meridiem) && hour === 12) hour = 0;
131 return new Date(Number(year), Number(month) - 1, Number(day), hour, Number(minute), 0, 0).getTime();
132 }
133
134 match = text.match(/\b([A-Za-z]{3,9})\s+(\d{1,2}),\s*(\d{4}),?\s*(\d{1,2}):(\d{2})\s*([AP]M)\b/i);
135 if (match) {
136 const [, monthText, day, year, hourText, minute, meridiem] = match;
137 const month = MONTH_INDEX_MAP[monthText.slice(0, 3).toLowerCase()];
138 if (month !== undefined) {
139 let hour = Number(hourText);
140 if (/pm/i.test(meridiem) && hour < 12) hour += 12;
141 if (/am/i.test(meridiem) && hour === 12) hour = 0;
142 return new Date(Number(year), month, Number(day), hour, Number(minute), 0, 0).getTime();
143 }
144 }
145
146 match = text.match(/今天\s*(\d{1,2}):(\d{2})/);
147 if (match) {
148 const now = new Date();
149 return new Date(now.getFullYear(), now.getMonth(), now.getDate(), Number(match[1]), Number(match[2]), 0, 0).getTime();
150 }
151
152 match = text.match(/昨天\s*(\d{1,2}):(\d{2})/);
153 if (match) {
154 const now = new Date();
155 now.setDate(now.getDate() - 1);
156 return new Date(now.getFullYear(), now.getMonth(), now.getDate(), Number(match[1]), Number(match[2]), 0, 0).getTime();
157 }
158
159 match = text.match(/^(\d{1,2}):(\d{2})$/);
160 if (match) {
161 const now = new Date();
162 return new Date(now.getFullYear(), now.getMonth(), now.getDate(), Number(match[1]), Number(match[2]), 0, 0).getTime();
163 }
164
165 return null;
166}
167
168function extractVerificationCode(text) {
169 const normalized = String(text || '');

Callers 1

getRowTimestampFunction · 0.85

Calls 1

normalizeTextFunction · 0.70

Tested by

no test coverage detected