github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/datetime/dayofyear.go (about)

     1  package datetime
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/MontFerret/ferret/pkg/runtime/core"
     7  	"github.com/MontFerret/ferret/pkg/runtime/values"
     8  	"github.com/MontFerret/ferret/pkg/runtime/values/types"
     9  )
    10  
    11  // DATE_DAYOFYEAR returns the day of year number of date.
    12  // The return value range from 1 to 365 (366 in a leap year).
    13  // @param {DateTime} date - Source DateTime.
    14  // @return {Int} - A day of year number.
    15  func DateDayOfYear(_ context.Context, args ...core.Value) (core.Value, error) {
    16  	err := core.ValidateArgs(args, 1, 1)
    17  	if err != nil {
    18  		return values.None, err
    19  	}
    20  
    21  	err = core.ValidateType(args[0], types.DateTime)
    22  	if err != nil {
    23  		return values.None, err
    24  	}
    25  
    26  	dayOfYear := args[0].(values.DateTime).YearDay()
    27  
    28  	return values.NewInt(dayOfYear), nil
    29  }