github.com/neohugo/neohugo@v0.123.8/resources/resource/dates.go (about) 1 // Copyright 2024 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package resource 15 16 import ( 17 "time" 18 19 "github.com/neohugo/neohugo/common/htime" 20 ) 21 22 // Dated wraps a "dated resource". These are the 4 dates that makes 23 // the date logic in Hugo. 24 type Dated interface { 25 // Date returns the date of the resource. 26 Date() time.Time 27 28 // Lastmod returns the last modification date of the resource. 29 Lastmod() time.Time 30 31 // PublishDate returns the publish date of the resource. 32 PublishDate() time.Time 33 34 // ExpiryDate returns the expiration date of the resource. 35 ExpiryDate() time.Time 36 } 37 38 // IsFuture returns whether the argument represents the future. 39 func IsFuture(d Dated) bool { 40 if d.PublishDate().IsZero() { 41 return false 42 } 43 44 return d.PublishDate().After(htime.Now()) 45 } 46 47 // IsExpired returns whether the argument is expired. 48 func IsExpired(d Dated) bool { 49 if d.ExpiryDate().IsZero() { 50 return false 51 } 52 return d.ExpiryDate().Before(htime.Now()) 53 } 54 55 // IsZeroDates returns true if all of the dates are zero. 56 func IsZeroDates(d Dated) bool { 57 return d.Date().IsZero() && d.Lastmod().IsZero() && d.ExpiryDate().IsZero() && d.PublishDate().IsZero() 58 }