MCPcopy Create free account
hub / github.com/ElementsProject/lightning / time_change

Function time_change

common/bolt12.c:681–715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

679}
680
681static bool time_change(u64 *new_start, u64 prevstart, u32 number,
682 bool (*add_time)(struct tm *tm, u32 number),
683 bool day_const)
684{
685 struct tm *tm_ptr;
686 struct tm tm;
687 time_t prev = prevstart, ret;
688
689 tm_ptr = gmtime(&prev);
690 /* Early exit, prev cannot be represented by struct tm. */
691 if (!tm_ptr)
692 return false;
693 tm = *tm_ptr;
694
695 for (;;) {
696 struct tm new_tm = tm;
697
698 /* The individual time components are int and can overflow. */
699 if (!add_time(&new_tm, number))
700 return false;
701
702 ret = mktime(&new_tm);
703
704 if (ret == (time_t)-1)
705 return false;
706
707 /* If we overflowed that month, try one less. */
708 if (!day_const || new_tm.tm_mday == tm.tm_mday)
709 break;
710 tm.tm_mday--;
711 }
712
713 *new_start = ret;
714 return true;
715}
716
717bool offer_period_start(u64 *start, u64 basetime, size_t n,
718 const struct recurrence *recur)

Callers 1

offer_period_startFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected