Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

support am pm monitor schedules

Developers Digest9fab26def4ce
diff --git a/apps/api/src/__tests__/snips/v2/types-validation.test.ts b/apps/api/src/__tests__/snips/v2/types-validation.test.ts
index b29bcf03e..3b846d4e6 100644
--- a/apps/api/src/__tests__/snips/v2/types-validation.test.ts
+++ b/apps/api/src/__tests__/snips/v2/types-validation.test.ts
@@ -1315,6 +1315,38 @@ describe("V2 Types Validation", () => {
});
});
+ it("should accept daily am/pm schedule text", () => {
+ const cases = [
+ ["daily at 9am", "0 9 * * *"],
+ ["daily at 9:30am", "30 9 * * *"],
+ ["daily at 5pm", "0 17 * * *"],
+ ["daily at 5:30 pm", "30 17 * * *"],
+ ["daily at 12am", "0 0 * * *"],
+ ["daily at 12pm", "0 12 * * *"],
+ ] as const;
+
+ for (const [text, cron] of cases) {
+ const result = updateMonitorSchema.parse({
+ schedule: { text },
+ });
+
+ expect(result.schedule).toEqual({
+ cron,
+ timezone: "UTC",
+ });
+ }
+ });
+
+ it("should reject invalid daily am/pm hours", () => {
+ expect(() =>
+ updateMonitorSchema.parse({
+ schedule: {
+ text: "daily at 13pm",
+ },
+ }),
+ ).toThrow("Daily schedule hour with am/pm must be between 1 and 12");
+ });
+
it("should reject ambiguous schedule definitions", () => {
expect(() =>
updateMonitorSchema.parse({
diff --git a/apps/api/src/services/monitoring/cron.ts b/apps/api/src/services/monitoring/cron.ts
index 68b544d0f..ca80ea2f5 100644
--- a/apps/api/src/services/monitoring/cron.ts
+++ b/apps/api/src/services/monitoring/cron.ts
@@ -69,11 +69,24 @@ export function parseMonitorScheduleText(input: string): string {
}
const dailyMatch = text.match(
- /^(?:daily|every day)(?: at (\d{1,2})(?::(\d{2}))?)?$/,
+ /^(?:daily|every day)(?: at (\d{1,2})(?::(\d{2}))?\s*(am|pm)?)?$/,
);
if (dailyMatch) {
- const hour = dailyMatch[1] === undefined ? 0 : Number(dailyMatch[1]);
+ let hour = dailyMatch[1] === undefined ? 0 : Number(dailyMatch[1]);
const minute = dailyMatch[2] === undefined ? 0 : Number(dailyMatch[2]);
+ const meridiem = dailyMatch[3];
+ if (meridiem !== undefined) {
+ if (!Number.isInteger(hour) || hour < 1 || hour > 12) {
+ throw new Error(
+ "Daily schedule hour with am/pm must be between 1 and 12",
+ );
+ }
+ if (meridiem === "am") {
+ hour = hour === 12 ? 0 : hour;
+ } else {
+ hour = hour === 12 ? 12 : hour + 12;
+ }
+ }
if (!Number.isInteger(hour) || hour < 0 || hour > 23) {
throw new Error("Daily schedule hour must be between 0 and 23");
}