// ------------------------------------------------------------------------ // Project atila // Active Thing (activething.com) git.activething.com/go // // File name rkey.go // Created by DEV // Modified 05/02/2024 // // Copyright 2024 activething.com // ------------------------------------------------------------------------ // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ------------------------------------------------------------------------ package times import ( "strconv" "time" ) type ( TimeFormatter interface { FormatTime (tme time.Time, dst []byte) []byte } FormatTimeFnc func (tme time.Time, dst []byte) []byte ) func (f FormatTimeFnc) FormatTime (tme time.Time, dst []byte) []byte { return f(tme,dst) } func WrapTimeFormatterQuoted (tmf TimeFormatter, qte byte) TimeFormatter { return FormatTimeFnc(func(tme time.Time, dst []byte) []byte { dst = append(dst, qte) dst = tmf.FormatTime(tme, dst) return append(dst, qte) }) } func TimeRFC3339Nano(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.RFC3339Nano) } func TimeANSIC(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.ANSIC) } func TimeUnixDate(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.UnixDate) } func TimeRubyDate(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.RubyDate) } func TimeRFC822(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.RFC822) } func TimeRFC822Z(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.RFC822Z) } func TimeRFC850(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.RFC850) } func TimeRFC1123(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.RFC1123) } func TimeRFC1123Z(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.RFC1123Z) } func TimeRFC3339(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.RFC3339) } func TimeKitchen(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.Kitchen) } func TimeISO8601(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, "2006-01-02T15:04:05.000Z0700") } func TimeEpoch(tme time.Time, dst []byte) []byte { return strconv.AppendFloat(dst, float64(tme.UnixNano())/float64(time.Second), 'f', -1, 64) } func TimeEpochMillis(tme time.Time, dst []byte) []byte { return strconv.AppendFloat(dst, float64(tme.UnixNano())/float64(time.Millisecond), 'f', -1, 64) } func TimeStamp(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.Stamp) } func TimeStampMilli(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.StampMilli) } func TimeStampMicro(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.StampMicro) } func TimeStampNano(tme time.Time, dst []byte) []byte { return tme.AppendFormat(dst, time.StampNano) } /* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. SIDDHARTA - HERMANN HESSE - ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */