// nextReleaseDay returns the date of the next release day, calculated based on
// the `releaseHourCheck`-th hour of the next `releaseDay` weekday
764729
func (e *Engine) nextReleaseDay() time.Time {
	now := e.timeManager.Now()
	nextRelease := e.midnight(now).Add(releaseHourCheck * time.Hour)
	if nextRelease.Weekday() == releaseDay {
		if nextRelease.Unix() <= now.Unix() {
			nextRelease = nextRelease.Add(24 * 7 * time.Hour)
		}
		return nextRelease
	}

	daysDue := int(nextRelease.Weekday()) - int(releaseDay)
	if daysDue <= 0 {
		daysDue = -daysDue
	} else {
		daysDue = 7 - daysDue
	}

	return nextRelease.Add(time.Duration(daysDue*24) * time.Hour)
}
1021597
func (c *Client) GetReleases() ([]Release, error) {
	r := c.NewRequest("GET", "/releases")
	resp, err := c.DoRequest(r)

	if err != nil {
		log.Printf("Error requesting releases  %v", err)
		return nil, err
	}
	defer resp.Body.Close()

	resBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Printf("Error reading releases request %v", resBody)
		return nil, err
	}

	releases := []Release{}
	err = json.Unmarshal(resBody, &releases)
	if err != nil {
		log.Printf("Error unmarshaling releases %v", err)
	}
	return releases, err
}
536012
func (sf *Sonyflake) NextID() (uint64, error) {
	const maskSequence = uint16(1<<BitLenSequence - 1)

	sf.mutex.Lock()
	defer sf.mutex.Unlock()

	current := currentElapsedTime(sf.startTime)
	if sf.elapsedTime < current {
		sf.elapsedTime = current
		sf.sequence = 0
	} else { // sf.elapsedTime >= current
		sf.sequence = (sf.sequence + 1) & maskSequence
		if sf.sequence == 0 {
			sf.elapsedTime++
			overtime := sf.elapsedTime - current
			time.Sleep(sleepTime((overtime)))
		}
	}

	return sf.toID()
}
1007870
func (o *CreateNew) SetReleaseLabel(v *string) *CreateNew {
	if o.ReleaseLabel = v; o.ReleaseLabel == nil {
		o.nullFields = append(o.nullFields, "ReleaseLabel")
	}
	return o
}
577559
func OriginalRelease(releases []*Release) *Release {

	if len(releases) == 0 {
		return nil
	}
	original := releases[0] // fall back on the first item

	for _, release := range releases {

		if !release.Date.IsZero() {

			if release.Date.Year() < original.Date.Year() || original.Date.IsZero() {
				original = release
			} else if release.Date.Year() == original.Date.Year() &&
				release.Date.Accuracy > Year {

				if original.Date.Accuracy == Year ||
					release.Date.Month() < original.Date.Month() {

					original = release

				} else if release.Date.Month() == original.Date.Month() &&
					release.Date.Accuracy > Month {

					if original.Date.Accuracy == Month ||
						release.Date.Day() < original.Date.Day() {
						original = release
					}
				}
			}
		}
	}

	return original
}
1167578
func (client DefaultClient) UpdateReleaseDate(mappingID int, releaseDate string) error {
	req, err := http.NewRequest("PUT", fmt.Sprintf("%s/rest/com.deniz.jira.mapping/latest/releaseDate/%d?releaseDate=%s", client.baseURL, mappingID, url.QueryEscape(releaseDate)), nil)
	if err != nil {
		return err
	}
	req.Header.Set("Accept", "application/json")
	req.SetBasicAuth(client.username, client.password)
	responseCode, data, err := client.consumeResponse(req)
	if err != nil {
		return err
	}
	if responseCode != http.StatusOK {
		logger.Printf("JIRA response: %s\n", string(data))
		return fmt.Errorf("error updating mapping release date.  Status code: %d.\n", responseCode)
	}
	return nil
}
1174818
func (c *Calendar) CountHolidayHoursWithOffset(start time.Time, offsetHour int) int {
	days := int(math.Ceil(float64(offsetHour) / float64(24)))

	holidayHours := 0
	day := 0
	for day <= days {
		date := start.AddDate(0, 0, day)
		if !c.IsWorkday(date) {
			holidayHours += 24
			days++
		}
		day++
	}

	return holidayHours
}
1002491
func releasesCreate(db *gorm.DB, release *Release) (*Release, error) {
	// Get the last release version for this app.
	v, err := releasesLastVersion(db, release.App.ID)
	if err != nil {
		return release, err
	}

	// Increment the release version.
	release.Version = v + 1

	if err := db.Create(release).Error; err != nil {
		return release, err
	}

	return release, nil
}
680737
func (s *persistentSequencer) NextID() (uint64, error) {

	// nextID will be the unique sequence number returned if no errors are
	// encountered.
	var nextID uint64

	// If our sequence batch has not been exhausted, we can allocate the
	// next identifier in the range.
	s.mu.Lock()
	defer s.mu.Unlock()

	if s.nextID < s.horizonID {
		nextID = s.nextID
		s.nextID++

		return nextID, nil
	}

	// Otherwise, our sequence batch has been exhausted. We use the last
	// known sequence number on disk to mark the beginning of the next
	// sequence batch, and allocate defaultSequenceBatchSize (1000) at a
	// time.
	//
	// NOTE: This also will happen on the first invocation after startup,
	// i.e. when nextID and horizonID are both 0. The next sequence batch to be
	// allocated will start from the last known tip on disk, which is fine
	// as we only require uniqueness of the allocated numbers.
	var nextHorizonID uint64
	if err := s.db.Update(func(tx *bbolt.Tx) error {
		nextIDBkt := tx.Bucket(nextPaymentIDKey)
		if nextIDBkt == nil {
			return ErrSequencerCorrupted
		}

		nextID = nextIDBkt.Sequence()
		nextHorizonID = nextID + defaultSequenceBatchSize

		// Cannot fail when used in Update.
		nextIDBkt.SetSequence(nextHorizonID)

		return nil
	}); err != nil {
		return 0, err
	}

	// Never assign index zero, to avoid collisions with the EmptyKeystone.
	if nextID == 0 {
		nextID++
	}

	// If our batch sequence allocation succeed, update our in-memory values
	// so we can continue to allocate sequence numbers without hitting disk.
	// The nextID is incremented by one in memory so the in can be used
	// issued directly on the next invocation.
	s.nextID = nextID + 1
	s.horizonID = nextHorizonID

	return nextID, nil
}
939106
func (t *RandomInterval) GetDelay() time.Duration {
	t.delay = time.Duration(rand.Int63n(t.maxDelay-t.minDelay) + t.minDelay)
	return t.delay
}
691872
func (s *releasesService) Release(ctx context.Context, release *Release, ss twelvefactor.StatusStream) error {
	a, err := newSchedulerApp(release)
	if err != nil {
		return err
	}
	return s.Scheduler.Submit(ctx, a, ss)
}
884333
func (this *Beanstalkd) Release(id uint64, pri, delay int) error {
	e := this.send("release %d %d %d\r\n", id, pri, delay)
	if e != nil {
		return e
	}
	reply, e := this.recvline()
	if e != nil {
		return e
	}
	_, e = fmt.Sscanf(reply, "RELEASED\r\n")
	if e != nil {
		return errors.New(reply)
	}
	return nil
}
102037
func (c *Client) ReleaseInfo(appIdentity string, releaseIdentity string) (*Release, error) {
	var release Release
	return &release, c.Get(&release, "/apps/"+appIdentity+"/releases/"+releaseIdentity)
}
967336
func (t *Trigger) needsDelay() (bool, time.Duration) {
	if t.params.MinInterval == time.Duration(0) {
		return false, 0
	}

	sleepTime := time.Since(t.lastTrigger.Add(t.params.MinInterval))
	return sleepTime < 0, sleepTime * -1
}
489791
func (s *Patch) SetReleaseDate(v time.Time) *Patch {
	s.ReleaseDate = &v
	return s
}
197290
func (p *Partition) NextSequence() int {
	p.mu.Lock()
	defer p.mu.Unlock()
	return p.nextSequence()
}
312485
func (c *WS2Client) LookupRelease(id MBID, inc ...string) (*Release, error) {
	a := &Release{ID: id}
	err := c.Lookup(a, inc...)

	return a, err
}