MCPcopy
hub / github.com/callumalpass/tasknotes / Time

Class Time

tests/__mocks__/ical.ts:219–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217
218 // Time class mock
219 Time: class Time {
220 year: number = 0;
221 month: number = 0;
222 day: number = 0;
223 hour: number = 0;
224 minute: number = 0;
225 second: number = 0;
226 isDate: boolean = false;
227
228 constructor(data?: any) {
229 if (data) {
230 Object.assign(this, data);
231 }
232 }
233
234 fromString(str: string): Time {
235 // Parse ICAL date/time format
236 if (str.includes('T')) {
237 // DateTime format: YYYYMMDDTHHMMSS or YYYYMMDDTHHMMSSZ
238 const dateTime = str.replace('Z', '');
239 const [datePart, timePart] = dateTime.split('T');
240
241 this.year = parseInt(datePart.substr(0, 4));
242 this.month = parseInt(datePart.substr(4, 2));
243 this.day = parseInt(datePart.substr(6, 2));
244
245 if (timePart) {
246 this.hour = parseInt(timePart.substr(0, 2));
247 this.minute = parseInt(timePart.substr(2, 2));
248 this.second = parseInt(timePart.substr(4, 2));
249 }
250 this.isDate = false;
251 } else {
252 // Date only format: YYYYMMDD
253 this.year = parseInt(str.substr(0, 4));
254 this.month = parseInt(str.substr(4, 2));
255 this.day = parseInt(str.substr(6, 2));
256 this.isDate = true;
257 }
258
259 return this;
260 }
261
262 toJSDate(): Date {
263 return new Date(this.year, this.month - 1, this.day, this.hour, this.minute, this.second);
264 }
265
266 toUnixTime(): number {
267 // Return Unix timestamp (seconds since epoch)
268 return Math.floor(this.toJSDate().getTime() / 1000);
269 }
270
271 toString(): string {
272 const year = this.year.toString().padStart(4, '0');
273 const month = this.month.toString().padStart(2, '0');
274 const day = this.day.toString().padStart(2, '0');
275
276 if (this.isDate) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected