// 2019 Rackspace, Inc. // // 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. // Time functions within the tools package is used to standardize time functions and formatting across the // application. This package is intended to be imported into the sub-packages that interact with time inputs. package tools import ( "strconv" "time" ) // Date is a package specific time struct used to create // customer methods on the time object. type Date struct { time.Time } // Timestamp will create a current epoch timestamp and return as a string for // similar formatting within mongo. func Timestamp() Date { return Date{time.Now().UTC()} } // Epoch takes a Date receiver and converts the value into // a Unix timestamp func (d Date) Epoch() string { return strconv.FormatInt(d.Unix(), 10) } // String takes a Date receiver and converts the value into // an RFC-3339 compliant time string. func (d Date) String() string { return d.Format(time.RFC3339) }