# Clarification of Temporal Schedule behaviour while using ScheduleInterval

**URL:** <https://community.temporal.io/t/clarification-of-temporal-schedule-behaviour-while-using-scheduleinterval/14788>\
**Category:** Community Support\
**Created:** [October 23, 2024, 10:21pm UTC](https://community.temporal.io/t/clarification-of-temporal-schedule-behaviour-while-using-scheduleinterval/14788 "2024-10-23T22:21:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paulo\_Roberto\_Maia\_S](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/paulo_roberto_maia_s/32/6181_2.png) [@Paulo\_Roberto\_Maia\_S](https://community.temporal.io/u/Paulo_Roberto_Maia_S)\
**Post date:** [October 23, 2024, 10:21pm UTC](https://community.temporal.io/t/clarification-of-temporal-schedule-behaviour-while-using-scheduleinterval/14788/1 "2024-10-23T22:21:20Z")

</div>

Hi everyone, we are implementing a feature using temporal schedules where we can define that a workflow should repeat at evey X time interval. I’m having some trouble while creating a weekly interval, as the first execution is always been scheduled for the next day first, then every week as I would expect. Could anyone provide some clarification on this behaviour ? I could not find anything in the docs.

The code im using is basically as follows

```auto
    var scheduleSpec =
        ScheduleSpec.newBuilder()
            .setStartAt(OffsetDateTime.now().toInstant())
             .setIntervals(List.of(new ScheduleIntervalSpec(Duration.of(7 , ChronoUnit.DAYS));

     var schedule = Schedule.newBuilder().setAction(action).setSpec(scheduleSpec.build()).build();
      scheduleClient.createSchedule(
          scheduleRunId,
          schedule,
          ScheduleOptions.newBuilder().build());

```

Running it at 2024-10-23 give me the following upcoming runs

 ![Screenshot 2024-10-23 at 19.18.04](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/5/5e735ea7bf3f54c65be1bac1a709d6b6fc80d102.png)

I would expect that the first run should have been at 2024-10-30 instead of 2024-10-24.

Could someone explain why it is scheduled to run at the next day ?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Paulo\_Roberto\_Maia\_S](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/paulo_roberto_maia_s/32/6181_2.png) [@Paulo\_Roberto\_Maia\_S](https://community.temporal.io/u/Paulo_Roberto_Maia_S)\
**Post date:** [October 23, 2024, 10:56pm UTC](https://community.temporal.io/t/clarification-of-temporal-schedule-behaviour-while-using-scheduleinterval/14788/2 "2024-10-23T22:56:58Z")

</div>

When I posted I got recommended this post here

> [@Scheduled Action Interval first run date calculation](https://community.temporal.io/t/scheduled-action-interval-first-run-date-calculation/13135/2):
>
> Hi @bobwere47 I think this issue answers both of your questions, Let me know if it helps, Antonio

The github discussion mentioned led to me finding that this seems to work in java. There were no `phase` parameter in java, but i implied it were the offset

```auto
var offset = getNextDate().toInstant().getEpochSecond()
          % (60L * 60L * 24L * 7L * recurrence.getInterval());
        scheduleSpec.setIntervals(List.of(new
            ScheduleIntervalSpec(Duration.ofDays(7L * recurrence.getInterval()),
            Duration.ofSeconds(offset))));

```

EDIT: Strangely when we start to get in the month range this formula seems not to work 100%. The original situal started to happen again.
