github.com/blend/go-sdk@v1.20220411.3/timeutil/end_of_month.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package timeutil
     9  
    10  import "time"
    11  
    12  // EndOfMonth returns the date that represents
    13  // the last day of the month for a given time.
    14  func EndOfMonth(t time.Time) time.Time {
    15  	t2 := t.AddDate(0, 1, 0)                                                // add a month
    16  	t3 := time.Date(t2.Year(), t2.Month(), 1, 00, 00, 00, 00, t.Location()) // move to YY-MM-01 00:00.00
    17  	t4 := t3.Add(-time.Nanosecond)                                          // subtract (1) nanosecond
    18  	return t4
    19  }