github.com/blend/go-sdk@v1.20240719.1/cron/once_at.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package cron
     9  
    10  import (
    11  	"fmt"
    12  	"time"
    13  )
    14  
    15  // Interface assertions.
    16  var (
    17  	_ Schedule     = (*OnceAtUTCSchedule)(nil)
    18  	_ fmt.Stringer = (*OnceAtUTCSchedule)(nil)
    19  )
    20  
    21  // OnceAtUTC returns a schedule that fires once at a given time.
    22  // It will never fire again unless reloaded.
    23  func OnceAtUTC(t time.Time) OnceAtUTCSchedule {
    24  	return OnceAtUTCSchedule{Time: t}
    25  }
    26  
    27  // OnceAtUTCSchedule is a schedule.
    28  type OnceAtUTCSchedule struct {
    29  	Time time.Time
    30  }
    31  
    32  // String returns a string representation of the schedule.
    33  func (oa OnceAtUTCSchedule) String() string {
    34  	return fmt.Sprintf("%s %s", StringScheduleOnceAt, oa.Time.Format(time.RFC3339))
    35  }
    36  
    37  // Next returns the next runtime.
    38  func (oa OnceAtUTCSchedule) Next(after time.Time) time.Time {
    39  	if after.IsZero() {
    40  		return oa.Time
    41  	}
    42  	if oa.Time.After(after) {
    43  		return oa.Time
    44  	}
    45  	return Zero
    46  }