Skip to content

Commit 660c805

Browse files
author
Ahmad Fikrizaman Bin Abd Rahim
committed
feat: start, end of hour and minute
1 parent 223a865 commit 660c805

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

carbon.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,26 @@ func (c *Carbon) DiffForHumans(d *Carbon, abs, absolute, short bool) (string, er
15211521
return c.Translator.chooseTrans(transID, t), nil
15221522
}
15231523

1524+
// StartOfHour returns the time at the start of every hour
1525+
func (c *Carbon) StartOfMinute() *Carbon {
1526+
return create(c.Year(), c.Month(), c.Day(), c.Hour(), c.Minute(), 0, 0, c.Location())
1527+
}
1528+
1529+
// EndOfHour returns the time at the start of every hour
1530+
func (c *Carbon) EndOfMinute() *Carbon {
1531+
return create(c.Year(), c.Month(), c.Day(), c.Hour(), c.Minute(), 59, maxNSecs, c.Location())
1532+
}
1533+
1534+
// StartOfHour returns the time at the start of every hour
1535+
func (c *Carbon) StartOfHour() *Carbon {
1536+
return create(c.Year(), c.Month(), c.Day(), c.Hour(), 0, 0, 0, c.Location())
1537+
}
1538+
1539+
// EndOfHour returns the time at the start of every hour
1540+
func (c *Carbon) EndOfHour() *Carbon {
1541+
return create(c.Year(), c.Month(), c.Day(), c.Hour(), 59, 59, maxNSecs, c.Location())
1542+
}
1543+
15241544
// StartOfDay returns the time at 00:00:00 of the same day
15251545
func (c *Carbon) StartOfDay() *Carbon {
15261546
return create(c.Year(), c.Month(), c.Day(), 0, 0, 0, 0, c.Location())

0 commit comments

Comments
 (0)