xpzouying/xiaohongshu-mcp · warning

定时发布时间不能超过14天,当前设置: %s,最晚可选: %s

Error message

定时发布时间不能超过14天,当前设置: %s,最晚可选: %s

What it means

PublishContent also caps scheduled publish times at 14 days into the future. A valid RFC3339 ScheduleAt later than now+14d is rejected, echoing the requested time and the latest allowed time. Both bounds are enforced in local server time at validation moment.

Source

Thrown at service.go:233

	var scheduleTime *time.Time
	if req.ScheduleAt != "" {
		t, err := time.Parse(time.RFC3339, req.ScheduleAt)
		if err != nil {
			return nil, fmt.Errorf("定时发布时间格式错误,请使用 ISO8601 格式: %v", err)
		}

		// 校验定时发布时间范围:1小时至14天
		now := time.Now()
		minTime := now.Add(1 * time.Hour)
		maxTime := now.Add(14 * 24 * time.Hour)

		if t.Before(minTime) {
			return nil, fmt.Errorf("定时发布时间必须至少在1小时后,当前设置: %s,最早可选: %s",
				t.Format("2006-01-02 15:04"), minTime.Format("2006-01-02 15:04"))
		}
		if t.After(maxTime) {
			return nil, fmt.Errorf("定时发布时间不能超过14天,当前设置: %s,最晚可选: %s",
				t.Format("2006-01-02 15:04"), maxTime.Format("2006-01-02 15:04"))
		}

		scheduleTime = &t
		logrus.Infof("设置定时发布时间: %s", t.Format("2006-01-02 15:04"))
	}

	content := xiaohongshu.PublishImageContent{
		Title:        req.Title,
		Content:      req.Content,
		Tags:         req.Tags,
		ImagePaths:   imagePaths,
		ScheduleTime: scheduleTime,
		IsOriginal:   req.IsOriginal,
		Visibility:   req.Visibility,
		Products:     req.Products,
	}

View on GitHub (pinned to 332d196854)

Solutions

  1. Cap the scheduled time at time.Now().Add(14*24*time.Hour) before calling the API
  2. Constrain the frontend date picker's max date to 14 days ahead
  3. If a longer lead time is needed, poll/queue locally and publish when within the 14-day window

Example fix

// before
req.ScheduleAt = time.Now().AddDate(0, 1, 0).Format(time.RFC3339) // 1 month ahead
// after
max := time.Now().Add(14 * 24 * time.Hour)
sched := time.Now().AddDate(0, 0, 13)
if sched.After(max) { sched = max }
req.ScheduleAt = sched.Format(time.RFC3339)
Defensive patterns

Strategy: validation

Validate before calling

if req.ScheduleAt != "" {
    t, _ := time.Parse(time.RFC3339, req.ScheduleAt)
    if max := time.Now().Add(14 * 24 * time.Hour); t.After(max) {
        return fmt.Errorf("schedule must be within 14 days, latest %s", max.Format(time.RFC3339))
    }
}

Type guard

func isWithin14Days(t time.Time) bool {
    return t.Before(time.Now().Add(14 * 24 * time.Hour))
}

Try / catch

resp, err := svc.PublishContent(ctx, req)
if err != nil && strings.Contains(err.Error(), "不能超过14天") {
    return fmt.Errorf("schedule too far out: %w", err)
}

Prevention

When it happens

Trigger: Calling PublishContent with ScheduleAt more than 14*24h after now, e.g. scheduling a post for next month.

Common situations: Users scheduling content weeks ahead; UI date pickers without a max-date constraint; DST/timezone shifts pushing a near-14-day time just past the limit.

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/c0471194555dfbc9. Report an issue: GitHub.