Skip to content

Commit

Permalink
Added missed datetime library (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex authored Mar 11, 2020
1 parent b08a232 commit e4464d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
44 changes: 23 additions & 21 deletions pkg/stdlib/datetime/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ package datetime

import "github.com/MontFerret/ferret/pkg/runtime/core"

func NewLib() map[string]core.Function {
return map[string]core.Function{
"NOW": Now,
"DATE": Date,
"DATE_DAYOFWEEK": DateDayOfWeek,
"DATE_YEAR": DateYear,
"DATE_MONTH": DateMonth,
"DATE_DAY": DateDay,
"DATE_HOUR": DateHour,
"DATE_MINUTE": DateMinute,
"DATE_SECOND": DateSecond,
"DATE_MILLISECOND": DateMillisecond,
"DATE_DAYOFYEAR": DateDayOfYear,
"DATE_LEAPYEAR": DateLeapYear,
"DATE_QUARTER": DateQuarter,
"DATE_DAYS_IN_MONTH": DateDaysInMonth,
"DATE_FORMAT": DateFormat,
"DATE_ADD": DateAdd,
"DATE_SUBTRACT": DateSubtract,
"DATE_DIFF": DateDiff,
}
func RegisterLib(ns core.Namespace) error {
return ns.RegisterFunctions(
core.NewFunctionsFromMap(map[string]core.Function{
"NOW": Now,
"DATE": Date,
"DATE_DAYOFWEEK": DateDayOfWeek,
"DATE_YEAR": DateYear,
"DATE_MONTH": DateMonth,
"DATE_DAY": DateDay,
"DATE_HOUR": DateHour,
"DATE_MINUTE": DateMinute,
"DATE_SECOND": DateSecond,
"DATE_MILLISECOND": DateMillisecond,
"DATE_DAYOFYEAR": DateDayOfYear,
"DATE_LEAPYEAR": DateLeapYear,
"DATE_QUARTER": DateQuarter,
"DATE_DAYS_IN_MONTH": DateDaysInMonth,
"DATE_FORMAT": DateFormat,
"DATE_ADD": DateAdd,
"DATE_SUBTRACT": DateSubtract,
"DATE_DIFF": DateDiff,
}),
)
}
5 changes: 5 additions & 0 deletions pkg/stdlib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/stdlib/arrays"
"github.com/MontFerret/ferret/pkg/stdlib/collections"
"github.com/MontFerret/ferret/pkg/stdlib/datetime"
"github.com/MontFerret/ferret/pkg/stdlib/html"
"github.com/MontFerret/ferret/pkg/stdlib/io"
"github.com/MontFerret/ferret/pkg/stdlib/math"
Expand All @@ -30,6 +31,10 @@ func RegisterLib(ns core.Namespace) error {
return err
}

if err := datetime.RegisterLib(ns); err != nil {
return err
}

if err := arrays.RegisterLib(ns); err != nil {
return err
}
Expand Down

0 comments on commit e4464d9

Please sign in to comment.