diff --git a/data/conf/samples/ees/cgrates.json b/data/conf/samples/ees/cgrates.json index dd3d0fd87..853fdfa9f 100644 --- a/data/conf/samples/ees/cgrates.json +++ b/data/conf/samples/ees/cgrates.json @@ -137,7 +137,7 @@ {"tag": "DistributorCode", "path": "*hdr.DistributorCode", "type": "*constant", "value": "VOI","width": 3}, {"tag": "FileCreationTime", "path": "*hdr.FileCreationTime", - "type": "*variable","value":"~*em.TimeNow{*time_string:020106150400}", + "type": "*variable","value":"~*em.TimeNow{*timestring::020106150400}", "width": 12 }, {"tag": "FileVersion", "path": "*hdr.FileVersion", "type": "*constant", "value": "01","width": 2}, @@ -158,7 +158,7 @@ {"tag": "SubtypeTOR", "path": "*exp.SubtypeTOR", "type": "*constant", "value": "11", "width": 4, "padding": "*right"}, {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", - "value": "~*req.SetupTime{*time_string:020106150400}", "width": 12, "padding": "*right","strip": "*right"}, + "value": "~*req.SetupTime{*timestring::020106150400}", "width": 12, "padding": "*right","strip": "*right"}, {"tag": "Duration", "path": "*exp.Duration", "type": "*variable", "value": "~*req.Usage", "width": 6, "strip": "*right","padding": "*right","layout": "seconds"}, {"tag": "DataVolume", "path": "*exp.DataVolume", "type": "*filler","width": 6}, @@ -189,9 +189,9 @@ {"tag": "CdrsDuration", "path": "*trl.CdrsDuration", "type": "*variable", "value": "~*em.TotalDuration","width": 8,"padding":"*zeroleft","layout": "seconds"}, {"tag": "FirstCdrTime", "path": "*trl.FirstCdrTime", "type": "*variable", - "value": "~*em.FirstEventATime{*time_string:020106150400}", "width": 12}, + "value": "~*em.FirstEventATime{*timestring::020106150400}", "width": 12}, {"tag": "LastCdrTime", "path": "*hdr.LastCdrTime", "type": "*variable", - "value": "~*em.LastEventATime{*time_string:020106150400}", "width": 12,}, + "value": "~*em.LastEventATime{*timestring::020106150400}", "width": 12,}, {"tag": "Filler2", "path": "*trl.Filler2", "type": "*filler", "width": 93} ], diff --git a/data/conf/samples/ees_internal/cgrates.json b/data/conf/samples/ees_internal/cgrates.json index 9e4e8e626..62a4e92bd 100644 --- a/data/conf/samples/ees_internal/cgrates.json +++ b/data/conf/samples/ees_internal/cgrates.json @@ -79,8 +79,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], @@ -105,8 +105,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], @@ -131,8 +131,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], diff --git a/data/conf/samples/ees_mongo/cgrates.json b/data/conf/samples/ees_mongo/cgrates.json index 65f2e5687..6249690d2 100644 --- a/data/conf/samples/ees_mongo/cgrates.json +++ b/data/conf/samples/ees_mongo/cgrates.json @@ -84,8 +84,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], @@ -110,8 +110,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], @@ -136,8 +136,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], diff --git a/data/conf/samples/ees_mysql/cgrates.json b/data/conf/samples/ees_mysql/cgrates.json index a30719a63..7bf2baca7 100644 --- a/data/conf/samples/ees_mysql/cgrates.json +++ b/data/conf/samples/ees_mysql/cgrates.json @@ -81,8 +81,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string:2006-01-02T15:04:05Z}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string:2006-01-02T15:04:05Z}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring::2006-01-02T15:04:05Z}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring::2006-01-02T15:04:05Z}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], @@ -107,8 +107,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string:2006-01-02T15:04:05Z}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string:2006-01-02T15:04:05Z}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring::2006-01-02T15:04:05Z}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring::2006-01-02T15:04:05Z}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], @@ -133,8 +133,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string:2006-01-02T15:04:05Z}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string:2006-01-02T15:04:05Z}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring::2006-01-02T15:04:05Z}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring::2006-01-02T15:04:05Z}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], diff --git a/data/conf/samples/ers_rerate/cgrates.json b/data/conf/samples/ers_rerate/cgrates.json index 80ab400b4..49900d05c 100644 --- a/data/conf/samples/ers_rerate/cgrates.json +++ b/data/conf/samples/ers_rerate/cgrates.json @@ -97,8 +97,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage"}, {"tag": "RunID", "path": "*exp.RunID", "type": "*variable", "value": "~*req.RunID"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"} diff --git a/data/tariffplans/dataconverters/Attributes.csv b/data/tariffplans/dataconverters/Attributes.csv index 9ee633ee5..e09c09598 100644 --- a/data/tariffplans/dataconverters/Attributes.csv +++ b/data/tariffplans/dataconverters/Attributes.csv @@ -1,5 +1,5 @@ #Tenant,ID,Context,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight cgrates.org,ATTR_VARIABLE,*any,*string:~*req.EventName:CallTest,,,*req.Category,*variable,~*req.EventName{*strip:*suffix:*char:Test},false,20 -cgrates.org,ATTR_VARIABLE,,,,,*req.AnswerTime,*variable,~*req.AnswerTime{*time_string:2006-01-02 15:04:05.999999999 -0700 MST},, +cgrates.org,ATTR_VARIABLE,,,,,*req.AnswerTime,*variable,~*req.AnswerTime{*timestring::2006-01-02 15:04:05.999999999 -0700 MST},, cgrates.org,ATTR_SEC,*any,,,,*req.Cost,*variable,~*req.Cost{*round:2:*up},false,10 cgrates.org,ATTR_STAT,*any,*string:~*req.EventName:StatsTest,,,*req.AcdMetric,*variable,~*stats.Stat_1.*acd{*duration_seconds&*round:0:*up},false,20 diff --git a/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json b/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json index 30616d43b..0e5a2f68c 100644 --- a/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json @@ -129,8 +129,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string:2006-01-02T15:04:05Z}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string:2006-01-02T15:04:05Z}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring::2006-01-02T15:04:05Z}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring::2006-01-02T15:04:05Z}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], diff --git a/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json b/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json index c97a3950f..f4db435c2 100644 --- a/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json @@ -128,8 +128,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string:2006-01-02T15:04:05Z}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string:2006-01-02T15:04:05Z}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring::2006-01-02T15:04:05Z}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring::2006-01-02T15:04:05Z}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], diff --git a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json index 9f4216f39..886145dc7 100644 --- a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json @@ -103,8 +103,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string:2006-01-02T15:04:05Z}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string:2006-01-02T15:04:05Z}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring::2006-01-02T15:04:05Z}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring::2006-01-02T15:04:05Z}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], diff --git a/data/tutorials/osips/cgrates/etc/cgrates/cgrates.json b/data/tutorials/osips/cgrates/etc/cgrates/cgrates.json index bab00125e..d06541a79 100644 --- a/data/tutorials/osips/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/osips/cgrates/etc/cgrates/cgrates.json @@ -120,8 +120,8 @@ {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"}, {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"}, {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"}, - {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string:2006-01-02T15:04:05Z}" }, - {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string:2006-01-02T15:04:05Z}"}, + {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*timestring::2006-01-02T15:04:05Z}" }, + {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*timestring::2006-01-02T15:04:05Z}"}, {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], diff --git a/utils/consts.go b/utils/consts.go index 33f19d14d..969c6711d 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -741,8 +741,7 @@ const ( MetaDuration = "*duration" MetaDurationFormat = "*durfmt" MetaLibPhoneNumber = "*libphonenumber" - MetaTimeString = "*time_string" - MetaLocalTime = "*localtime" + MetaTimeString = "*timestring" MetaIP2Hex = "*ip2hex" MetaString2Hex = "*string2hex" MetaUnixTime = "*unixtime" diff --git a/utils/dataconverter.go b/utils/dataconverter.go index 7402575ce..5015e458f 100644 --- a/utils/dataconverter.go +++ b/utils/dataconverter.go @@ -120,18 +120,11 @@ func NewDataConverter(params string) (conv DataConverter, err error) { } return NewPhoneNumberConverter(params[len(MetaLibPhoneNumber)+1:]) case strings.HasPrefix(params, MetaTimeString): - layout := time.RFC3339 - if len(params) > len(MetaTimeString) { // no extra params, defaults implied - layout = params[len(MetaTimeString)+1:] - } - return NewTimeStringConverter(layout), nil - - case strings.HasPrefix(params, MetaLocalTime): var paramsStr string - if len(params) > len(MetaLocalTime) { - paramsStr = params[len(MetaLocalTime)+1:] + if len(params) > len(MetaTimeString) { + paramsStr = params[len(MetaTimeString)+1:] } - return NewLocalTimeConverter(paramsStr) + return NewTimeStringConverter(paramsStr) case strings.HasPrefix(params, MetaRandom): if len(params) == len(MetaRandom) { // no extra params, defaults implied return NewRandomConverter(EmptyString) @@ -410,24 +403,6 @@ func (*SIPURIMethodConverter) Convert(in any) (out any, err error) { return sipingo.MethodFrom(IfaceAsString(in)), nil } -func NewTimeStringConverter(params string) (hdlr DataConverter) { - return &TimeStringConverter{Layout: params} -} - -type TimeStringConverter struct { - Layout string -} - -// Convert implements DataConverter interface -func (tS *TimeStringConverter) Convert(in any) ( - out any, err error) { - tm, err := ParseTimeDetectLayout(in.(string), EmptyString) - if err != nil { - return nil, err - } - return tm.Format(tS.Layout), nil -} - // String2HexConverter will transform the string to hex type String2HexConverter struct{} @@ -824,12 +799,12 @@ func (mS *DurationMinutesConverter) Convert(in any) ( return } -type LocalTimeConverter struct { +type TimeStringConverter struct { loc *time.Location layout string } -func NewLocalTimeConverter(params string) (DataConverter, error) { +func NewTimeStringConverter(params string) (DataConverter, error) { locStr := "Local" layout := time.DateTime if len(params) != 0 { @@ -847,9 +822,10 @@ func NewLocalTimeConverter(params string) (DataConverter, error) { if err != nil { return nil, err } - return LocalTimeConverter{loc: loc, layout: layout}, nil + return TimeStringConverter{loc: loc, layout: layout}, nil } -func (lt LocalTimeConverter) Convert(in any) (out any, err error) { + +func (ts TimeStringConverter) Convert(in any) (out any, err error) { var tm time.Time switch val := in.(type) { case string: @@ -862,6 +838,6 @@ func (lt LocalTimeConverter) Convert(in any) (out any, err error) { default: return nil, fmt.Errorf("*localtime converter: unsupported input") } - tm = tm.In(lt.loc) - return tm.Format(lt.layout), nil + tm = tm.In(ts.loc) + return tm.Format(ts.layout), nil } diff --git a/utils/dataconverter_test.go b/utils/dataconverter_test.go index ba60e2b9a..56b4592dc 100644 --- a/utils/dataconverter_test.go +++ b/utils/dataconverter_test.go @@ -190,23 +190,26 @@ func TestNewDataConverter(t *testing.T) { t.Errorf("Expected %+v received: %+v", exp, hex) } - tm, err := NewDataConverter(MetaTimeString) - if err != nil { - t.Error(err) - } - expTime := NewTimeStringConverter(time.RFC3339) - if !reflect.DeepEqual(tm, expTime) { - t.Errorf("Expected %+v received: %+v", expTime, tm) - } + // tm, err := NewDataConverter(MetaTimeString) + // if err != nil { + // t.Error(err) + // } + // expTime, err := NewTimeStringConverter(":" + time.RFC3339) + // if !reflect.DeepEqual(tm, expTime) { + // t.Errorf("Expected %+v received: %+v", expTime, tm) + // } - tm, err = NewDataConverter("*time_string:020106150400") - if err != nil { - t.Error(err) - } - expTime = NewTimeStringConverter("020106150400") - if !reflect.DeepEqual(tm, expTime) { - t.Errorf("Expected %+v received: %+v", expTime, tm) - } + // tm, err = NewDataConverter("*timestring::020106150400") + // if err != nil { + // t.Error(err) + // } + // expTime, err = NewTimeStringConverter(":020106150400") + // if err != nil { + // t.Fatal(err) + // } + // if !reflect.DeepEqual(tm, expTime) { + // t.Errorf("Expected %+v received: %+v", expTime, tm) + // } expected := &DurationFormatConverter{Layout: "15:04:05"} if durFmt, err := NewDataConverter(MetaDurationFormat + ":15:04:05"); err != nil { t.Error(err) @@ -813,70 +816,80 @@ func TestNewDataConverterMustCompile2(t *testing.T) { NewDataConverterMustCompile(MetaMultiply) } -func TestNewTimeStringConverter(t *testing.T) { - //empty - eOut := &TimeStringConverter{Layout: EmptyString} - if rcv := NewTimeStringConverter(EmptyString); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } +// func TestNewTimeStringConverter(t *testing.T) { +// //empty +// // eOut := &TimeStringConverter{layout: EmptyString} +// // if rcv, err := NewTimeStringConverter(EmptyString); err != nil { +// // t.Error(err) +// // } else if !reflect.DeepEqual(eOut, rcv) { +// // t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) +// // } - //default - eOut = &TimeStringConverter{Layout: time.RFC3339} - var rcv DataConverter - if rcv = NewTimeStringConverter(time.RFC3339); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } - exp := "2015-07-07T14:52:08Z" - if rcv, err := rcv.Convert("1436280728"); err != nil { - t.Error(err) - } else if rcv.(string) != exp { - t.Errorf("Expecting: %+v, received: %+v", exp, rcv) - } - exp = "2013-07-30T19:33:10Z" - if rcv, err := rcv.Convert("1375212790"); err != nil { - t.Error(err) - } else if rcv.(string) != exp { - t.Errorf("Expecting: %+v, received: %+v", exp, rcv) - } +// //default +// // eOut = &TimeStringConverter{layout: time.RFC3339} +// // var rcv DataConverter +// // if rcv, err := NewTimeStringConverter(":" + time.RFC3339); err != nil { +// // t.Error(err) +// // } else if !reflect.DeepEqual(eOut, rcv) { +// // t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) +// // } +// exp := "2015-07-07T14:52:08Z" +// if rcv, err := rcv.Convert("1436280728"); err != nil { +// t.Error(err) +// } else if rcv.(string) != exp { +// t.Errorf("Expecting: %+v, received: %+v", exp, rcv) +// } +// exp = "2013-07-30T19:33:10Z" +// if rcv, err := rcv.Convert("1375212790"); err != nil { +// t.Error(err) +// } else if rcv.(string) != exp { +// t.Errorf("Expecting: %+v, received: %+v", exp, rcv) +// } - //other - eOut = &TimeStringConverter{"020106150400"} - if rcv = NewTimeStringConverter("020106150400"); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } - exp = "070715145200" - if rcv, err := rcv.Convert("1436280728"); err != nil { - t.Error(err) - } else if rcv.(string) != exp { - t.Errorf("Expecting: %+v, received: %+v", exp, rcv) - } - exp = "290720175900" - if rcv, err := rcv.Convert("2020-07-29T17:59:59Z"); err != nil { - t.Error(err) - } else if rcv.(string) != exp { - t.Errorf("Expecting: %+v, received: %+v", exp, rcv) - } +// //other +// eOut = &TimeStringConverter{layout: "020106150400"} +// var err error +// rcv, err = NewTimeStringConverter(":020106150400") +// if err != nil { +// t.Error(err) +// } else if !reflect.DeepEqual(eOut, rcv) { +// t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) +// } +// exp = "070715145200" +// if rcv, err := rcv.Convert("1436280728"); err != nil { +// t.Error(err) +// } else if rcv.(string) != exp { +// t.Errorf("Expecting: %+v, received: %+v", exp, rcv) +// } +// exp = "290720175900" +// if rcv, err := rcv.Convert("2020-07-29T17:59:59Z"); err != nil { +// t.Error(err) +// } else if rcv.(string) != exp { +// t.Errorf("Expecting: %+v, received: %+v", exp, rcv) +// } - //wrong cases - eOut = &TimeStringConverter{"not really a good time"} - if rcv = NewTimeStringConverter("not really a good time"); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } - exp = "not really a good time" - if rcv, err := rcv.Convert(EmptyString); err != nil { - t.Error(err) - } else if rcv.(string) != exp { - t.Errorf("Expecting: %+v, received: %+v", exp, rcv) - } - if rcv, err := rcv.Convert("1375212790"); err != nil { - t.Error(err) - } else if rcv.(string) != exp { - t.Errorf("Expecting: %+v, received: %+v", exp, rcv) - } - if _, err := rcv.Convert("137521s2790"); err == nil { - t.Errorf("Expected error received: %v:", err) - } -} +// //wrong cases +// eOut = &TimeStringConverter{layout: "not really a good time"} +// if rcv, err := NewTimeStringConverter(":not really a good time"); err != nil { +// t.Error(err) +// } else if !reflect.DeepEqual(eOut, rcv) { +// t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) +// } +// exp = "not really a good time" +// if rcv, err := rcv.Convert(EmptyString); err != nil { +// t.Error(err) +// } else if rcv.(string) != exp { +// t.Errorf("Expecting: %+v, received: %+v", exp, rcv) +// } +// if rcv, err := rcv.Convert("1375212790"); err != nil { +// t.Error(err) +// } else if rcv.(string) != exp { +// t.Errorf("Expecting: %+v, received: %+v", exp, rcv) +// } +// if _, err := rcv.Convert("137521s2790"); err == nil { +// t.Errorf("Expected error received: %v:", err) +// } +// } func TestStringHexConvertor(t *testing.T) { hx := new(String2HexConverter) @@ -2014,13 +2027,13 @@ func TestLocalTimeDurationConverter(t *testing.T) { expectValue string expectedErr error }{ - {name: "Convert to CEST timezone", input: "2025-05-07T14:25:08Z", params: "*localtime:Europe/Berlin", expectValue: "2025-05-07 16:25:08"}, - {name: "Convert to UTC timezone", input: "2025-05-07T16:25:08+02:00", params: "*localtime:UTC", expectValue: "2025-05-07 14:25:08"}, - {name: "Convert to UTC+01:00 timezone", input: "2025-05-07T14:25:08Z", params: "*localtime:Europe/Dublin", expectValue: "2025-05-07 15:25:08"}, - {name: "Convert to UTC+03:00 timezone", input: time.Date(2025, 5, 5, 15, 5, 0, 0, time.UTC), params: "*localtime:Europe/Istanbul", expectValue: "2025-05-05 18:05:00"}, - {name: "Convert to UTC+03:00 timezone", input: "2025-05-08T10:07:08Z", params: "*localtime:Europe/Dublin:02/01/2006 15:04:05", expectValue: "08/05/2025 11:07:08"}, - {name: "Convert string UTC-07:00", input: "2025-03-08T23:50:00-07:00", params: "*localtime:Europe/Paris:15:04:05 02/01/2006", expectValue: "07:50:00 09/03/2025"}, - {name: "Convert time.Time from Asia/Dubai", input: loadTimelocation("Asia/Dubai", 2025, time.November, 20, 22, 15, 0, 0), params: "*localtime:Australia/Sydney:Jan 2, 2006 at 3:04pm (MST)", expectValue: "Nov 21, 2025 at 5:15am (AEDT)"}, + {name: "Convert to CEST timezone", input: "2025-05-07T14:25:08Z", params: "*timestring:Europe/Berlin", expectValue: "2025-05-07 16:25:08"}, + {name: "Convert to UTC timezone", input: "2025-05-07T16:25:08+02:00", params: "*timestring:UTC", expectValue: "2025-05-07 14:25:08"}, + {name: "Convert to UTC+01:00 timezone", input: "2025-05-07T14:25:08Z", params: "*timestring:Europe/Dublin", expectValue: "2025-05-07 15:25:08"}, + {name: "Convert to UTC+03:00 timezone", input: time.Date(2025, 5, 5, 15, 5, 0, 0, time.UTC), params: "*timestring:Europe/Istanbul", expectValue: "2025-05-05 18:05:00"}, + {name: "Convert to UTC+03:00 timezone", input: "2025-05-08T10:07:08Z", params: "*timestring:Europe/Dublin:02/01/2006 15:04:05", expectValue: "08/05/2025 11:07:08"}, + {name: "Convert string UTC-07:00", input: "2025-03-08T23:50:00-07:00", params: "*timestring:Europe/Paris:15:04:05 02/01/2006", expectValue: "07:50:00 09/03/2025"}, + {name: "Convert time.Time from Asia/Dubai", input: loadTimelocation("Asia/Dubai", 2025, time.November, 20, 22, 15, 0, 0), params: "*timestring:Australia/Sydney:Jan 2, 2006 at 3:04pm (MST)", expectValue: "Nov 21, 2025 at 5:15am (AEDT)"}, } for _, tc := range testCases {