MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / validateTimeBlock

Function validateTimeBlock

src/utils/helpers.ts:625–688  ·  view source on GitHub ↗
(timeblock: unknown)

Source from the content-addressed store, hash-verified

623}
624
625export function validateTimeBlock(timeblock: unknown): timeblock is TimeBlock {
626 if (!timeblock || typeof timeblock !== "object") {
627 return false;
628 }
629 const block = timeblock as Partial<TimeBlock>;
630
631 // Required fields
632 if (!block.id || typeof block.id !== "string") {
633 return false;
634 }
635
636 if (!block.title || typeof block.title !== "string") {
637 return false;
638 }
639
640 if (!block.startTime || typeof block.startTime !== "string") {
641 return false;
642 }
643
644 if (!block.endTime || typeof block.endTime !== "string") {
645 return false;
646 }
647
648 const startMinutes = parseTimeBlockMinutes(block.startTime);
649 const parsedEndMinutes = parseTimeBlockMinutes(block.endTime, true);
650 if (startMinutes === null || parsedEndMinutes === null) {
651 return false;
652 }
653
654 const endMinutes =
655 block.endTime === "00:00" && startMinutes > 0 ? MINUTES_PER_DAY : parsedEndMinutes;
656
657 if (endMinutes <= startMinutes) {
658 return false;
659 }
660
661 // Optional fields validation
662 if (block.attachments && !Array.isArray(block.attachments)) {
663 return false;
664 }
665
666 if (block.attachments) {
667 for (const attachment of block.attachments) {
668 if (typeof attachment !== "string") {
669 return false;
670 }
671 // Optional: validate markdown link format (basic check)
672 // Could be [[WikiLink]] or [Text](path) format
673 if (!attachment.trim()) {
674 return false;
675 }
676 }
677 }
678
679 if (block.color && typeof block.color !== "string") {
680 return false;
681 }
682

Callers 2

helpers.test.tsFile · 0.90

Calls 1

parseTimeBlockMinutesFunction · 0.85

Tested by

no test coverage detected