...

Source file src/oss.terrastruct.com/d2/lib/time/time.go

Documentation: oss.terrastruct.com/d2/lib/time

     1  package time
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"oss.terrastruct.com/d2/lib/env"
     8  )
     9  
    10  func HumanDate(t time.Time) string {
    11  	local := t.Local()
    12  	return local.Format(time.RFC822)
    13  }
    14  
    15  // WithTimeout returns context.WithTimeout(ctx, timeout) but timeout is overridden with D2_TIMEOUT if set
    16  func WithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc) {
    17  	t := timeout
    18  	if seconds, has := env.Timeout(); has {
    19  		t = time.Duration(seconds) * time.Second
    20  	}
    21  	if t <= 0 {
    22  		return ctx, func() {}
    23  	}
    24  
    25  	return context.WithTimeout(ctx, t)
    26  }
    27  

View as plain text