Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
### Fixed

- `planCalendarEdit` no longer clears other occurrences' completed or skipped history when moving a scheduled-anchored recurring task. Moves without a `recurrence_original_date` (such as Google-synced or legacy off-pattern tasks) clear only the landing day when it is already recorded; completion-anchored tasks keep clearing recorded instances on or after the new date. Thanks to @martin-forge for reporting (TaskNotes #2691).
- Generated mdbase task types accept floating scheduled and due times written by TaskNotes. Thanks to @iantierney for reporting (TaskNotes #2706).
- Generated mdbase task types and the `tasknotes.task` 0.3.0-rc.7 contract accept floating `due`, `scheduled`, `dateCreated`, and `dateModified` values through the `local-date-time` format. Pack 0.3.0-rc.23 upgrades all earlier starters, including the TaskNotes #2706 fix.
- Calendar conversion accepts fractional seconds of any length and truncates to millisecond precision. Timestamp validation, task updates, and time tracking calculations use the collection timezone when callers supply it.

## 0.3.2 - 2026-11-20

Expand Down
2 changes: 1 addition & 1 deletion scripts/sync-tasknotes-pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const generatedPath = path.resolve(
"../src/generated/tasknotes-type-pack.json"
);
const source = await readFile(
path.join(contractsRoot, "dist/packs/tasknotes.task/0.3.0-rc.22.json"),
path.join(contractsRoot, "dist/packs/tasknotes.task/0.3.0-rc.23.json"),
"utf8"
);

Expand Down
13 changes: 11 additions & 2 deletions src/calendar-date.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Calendar dates are civil values in an explicit IANA zone, never the process zone.
const DAY = 86_400_000;
const CIVIL = /^(\d{4}-\d{2}-\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?)?$/;
const CIVIL = /^(\d{4}-\d{2}-\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?)?$/;

export function calendarDay(value: string): string {
return value.slice(0, 10);
Expand Down Expand Up @@ -65,6 +65,15 @@ export function calendarDateToInstant(value: string, timezone: string): number {
return cached !== undefined ? cached : remember(toInstant, key, dateToInstant(value, timezone));
}

export function timestampForComparison(value: string, timezone?: string): number {
if (timezone === undefined) return Date.parse(value);
try {
return calendarDateToInstant(value.trim(), timezone);
} catch {
return NaN;
}
}

function dateToInstant(value: string, timezone: string): number {
const match = CIVIL.exec(value);
if (!match) {
Expand All @@ -89,7 +98,7 @@ function dateToInstant(value: string, timezone: string): number {
const matching = candidates.filter((ms) => civilAt(ms, format) === civil);
return (
(matching.length ? Math.min(...matching) : Math.max(...candidates)) +
Number(fraction.padEnd(3, "0"))
Number(fraction.slice(0, 3).padEnd(3, "0"))
);
}

Expand Down
11 changes: 8 additions & 3 deletions src/conformance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function executeConformanceOperation(
case "validation.core_evaluate":
return ok(validateCoreConformance(input));
case "validation.time_entries":
return ok(validateTimeEntries(input.entries));
return ok(validateTimeEntries(input.entries, stringOrUndefined(input.timezone)));
case "op.mutate_with_validation":
return mutateWithValidation(input);
case "op.update_patch":
Expand Down Expand Up @@ -289,7 +289,9 @@ export function executeConformanceOperation(
case "time.auto_stop_on_complete":
return ok({ value: true });
case "time.report_totals":
return ok({ minutes: calculateTotalTrackedMinutes(arrayValue(input.entries) as TimeEntry[]) });
return ok({
minutes: calculateTotalTrackedMinutes(arrayValue(input.entries) as TimeEntry[], stringOrUndefined(input.timezone)),
});
default:
return err(`Unsupported operation: ${operation}`, { operation, code: "unsupported_operation" });
}
Expand Down Expand Up @@ -500,6 +502,7 @@ function addConformanceIssue(
function validateCoreConformance(input: Record<string, unknown>): Record<string, unknown> {
const fields = asRecord(input.fields);
const frontmatter = asRecord(input.frontmatter);
const timezone = stringOrUndefined(input.timezone);
const mapping = buildSpecFieldMapping(fields, stringOrUndefined(input.displayNameKey));
const normalized = normalizeSpecFrontmatter(frontmatter, mapping);
const issues: Record<string, unknown>[] = [];
Expand Down Expand Up @@ -542,7 +545,9 @@ function validateCoreConformance(input: Record<string, unknown>): Record<string,
}
if (typeof normalized.dateCreated === "string" && typeof normalized.dateModified === "string") {
try {
if (parseDateToUTC(normalized.dateModified).getTime() < parseDateToUTC(normalized.dateCreated).getTime()) {
const created = parseDateToUTC(normalized.dateCreated, timezone).getTime();
const modified = parseDateToUTC(normalized.dateModified, timezone).getTime();
if (modified < created) {
addConformanceIssue(issues, "date_modified_before_created", "error", mapping.roleToField.dateModified);
}
} catch {
Expand Down
59 changes: 29 additions & 30 deletions src/date.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { calendarDateToInstant } from "./calendar-date";

const DATE_ONLY_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
const STRICT_DATETIME_RE =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d{1,3})?(?:Z|([+-])(\d{2}):(\d{2}))?$/;
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(Z|([+-])(\d{2}):(\d{2}))?$/;
const RELAXED_DATETIME_RE =
/^(\d{4})-(\d{2})-(\d{2})(?:T| )(\d{2}):(\d{2})(?::(\d{2})(\.\d{1,3})?)?(Z|([+-])(\d{2}):(\d{2}))?$/;
/^(\d{4})-(\d{2})-(\d{2})(?:T| )(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(Z|([+-])(\d{2}):(\d{2}))?$/;

export type DateTimeRangeBound = "from" | "to";

export function parseDateToUTC(dateString: string): Date {
/** Date-only values use a UTC anchor. Floating date-times use the supplied zone or the system zone. */
export function parseDateToUTC(dateString: string, timezone?: string): Date {
const trimmed = requireDateString(dateString);
const dateOnlyMatch = trimmed.match(DATE_ONLY_RE);
if (dateOnlyMatch) {
Expand All @@ -20,15 +23,7 @@ export function parseDateToUTC(dateString: string): Date {
return new Date(Date.UTC(y, m - 1, d, 0, 0, 0, 0));
}

if (!isStrictDateTime(trimmed)) {
throw new Error(`Invalid date "${dateString}".`);
}

const parsed = new Date(trimmed);
if (!isValidDate(parsed)) {
throw new Error(`Invalid date "${dateString}".`);
}
return parsed;
return parseStrictDateTime(trimmed, dateString, timezone);
}

export function parseDateToLocal(dateString: string): Date {
Expand All @@ -51,15 +46,7 @@ export function parseDateToLocal(dateString: string): Date {
return parsed;
}

if (!isStrictDateTime(trimmed)) {
throw new Error(`Invalid date "${dateString}".`);
}

const parsed = new Date(trimmed);
if (!isValidDate(parsed)) {
throw new Error(`Invalid date "${dateString}".`);
}
return parsed;
return parseStrictDateTime(trimmed, dateString);
}

export function formatDateForStorage(date: Date): string {
Expand Down Expand Up @@ -227,7 +214,7 @@ export function resolveDateTimeRangeBound(value: string, bound: DateTimeRangeBou
const hh = Number(hours);
const mm = Number(minutes);
const ss = seconds === undefined ? (bound === "to" ? 59 : 0) : Number(seconds);
const ms = fraction ? Number(fraction.slice(1).padEnd(3, "0")) : bound === "to" ? 999 : 0;
const ms = fraction ? Number(fraction.slice(1, 4).padEnd(3, "0")) : bound === "to" ? 999 : 0;

if (
!isValidCalendarDate(y, m, d) ||
Expand Down Expand Up @@ -266,16 +253,28 @@ function requireDateString(value: string, message = "Date string cannot be empty
return value.trim();
}

function isStrictDateTime(value: string): boolean {
function parseStrictDateTime(value: string, original: string, timezone?: string): Date {
const match = value.match(STRICT_DATETIME_RE);
if (!match) return false;
if (!match) throw new Error(`Invalid date "${original}".`);

const [, year, month, day, hours, minutes, seconds, , tzSign, tzHours, tzMinutes] = match;
return (
isValidCalendarDate(Number(year), Number(month), Number(day)) &&
isValidClockTime(Number(hours), Number(minutes), Number(seconds)) &&
isValidOffset(tzSign, tzHours, tzMinutes)
);
const [, year, month, day, hours, minutes, seconds, fraction, offset, tzSign, tzHours, tzMinutes] = match;
if (
(offset && seconds === undefined) ||
!isValidCalendarDate(Number(year), Number(month), Number(day)) ||
!isValidClockTime(Number(hours), Number(minutes), Number(seconds ?? "0")) ||
!isValidOffset(tzSign, tzHours, tzMinutes)
) {
throw new Error(`Invalid date "${original}".`);
}

if (timezone !== undefined && !offset) {
return new Date(calendarDateToInstant(value, timezone));
}
const normalized = `${year}-${month}-${day}T${hours}:${minutes}:${seconds ?? "00"}` +
`${fraction?.slice(0, 4).padEnd(4, "0") ?? ".000"}${offset ?? ""}`;
const parsed = new Date(normalized);
if (!isValidDate(parsed)) throw new Error(`Invalid date "${original}".`);
return parsed;
}

function isValidCalendarDate(year: number, month: number, day: number): boolean {
Expand Down
36 changes: 30 additions & 6 deletions src/generated/tasknotes-data-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const TASKNOTES_TASK_SCHEMA = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://tasknotes.dev/schemas/tasknotes-task.schema.json",
"title": "TaskNotes portable task view",
"description": "The storage-neutral record view exposed by the tasknotes.task 0.3.0-rc.6 record contract.",
"description": "The storage-neutral record view exposed by the tasknotes.task 0.3.0-rc.7 record contract.",
"type": "object",
"required": [
"status",
Expand Down Expand Up @@ -38,6 +38,10 @@ export const TASKNOTES_TASK_SCHEMA = {
{
"type": "string",
"format": "date-time"
},
{
"type": "string",
"format": "local-date-time"
}
]
},
Expand All @@ -50,6 +54,10 @@ export const TASKNOTES_TASK_SCHEMA = {
{
"type": "string",
"format": "date-time"
},
{
"type": "string",
"format": "local-date-time"
}
]
},
Expand Down Expand Up @@ -92,12 +100,28 @@ export const TASKNOTES_TASK_SCHEMA = {
"format": "date"
},
"dateCreated": {
"type": "string",
"format": "date-time"
"anyOf": [
{
"type": "string",
"format": "date-time"
},
{
"type": "string",
"format": "local-date-time"
}
]
},
"dateModified": {
"type": "string",
"format": "date-time"
"anyOf": [
{
"type": "string",
"format": "date-time"
},
{
"type": "string",
"format": "local-date-time"
}
]
},
"recurrence": {
"type": "string"
Expand Down Expand Up @@ -208,7 +232,7 @@ export const TASKNOTES_TASK_BINDING_SCHEMA = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://tasknotes.dev/schemas/tasknotes-task-binding.schema.json",
"title": "TaskNotes task data-contract binding",
"description": "Semantic configuration supplied by an mdbase type that implements tasknotes.task 0.3.0-rc.6. App behaviour, such as templates, archive moves, status cycling and natural-language triggers, lives in the app's tasknotes.settings record instead.",
"description": "Semantic configuration supplied by an mdbase type that implements tasknotes.task 0.3.0-rc.7. App behaviour, such as templates, archive moves, status cycling and natural-language triggers, lives in the app's tasknotes.settings record instead.",
"type": "object",
"required": [
"profiles",
Expand Down
Loading
Loading