package
1.0.10
Repository: https://github.com/scrawld/library.git
Documentation: pkg.go.dev

# Functions

* * Assign 结构体赋值 * * Example: * * type User1 struct { * Name string * Age int * } * * type User2 struct { * Name string * Age int * } * * u1 := &User1{Name: "zhangsan", Age: 20} * u2 := &User2{} * * Assign(u1, u2) * fmt.Println(u1, u2) */.
DaysBetween 计算两个时间之间的天数差异.
No description provided by the author
DtToTime 日期缩写转时间.
* * ExportCSV 导出csv * * Example: * * type Person struct { * Name string `csv:"Name"` * Age int `csv:"Age"` * Email string `csv:"Email"` * } * tbody := []Person{ * {Name: "Alice", Age: 25, Email: "[email protected]"}, * {Name: "Bob", Age: 30, Email: "[email protected]"}, * } * buf, err := ExportCSV(Person{}, tbody, true) * if err != nil { * // * } * os.WriteFile("test.csv", buf.Bytes(), 0644) */.
* * ExportExcel 导出excel * * Example: * * type ReportExcel struct { * Dt string `excel:"日期"` * NewUsers int64 `excel:"注册人数"` * LoginUsers int64 `excel:"登录人数"` * Tmp int64 `excel:"-"` * } * tbody := []ReportExcel{ * {Dt: "2006-01-02", NewUsers: 1, LoginUsers: 2, Tmp: 1}, * } * buf, err := ExportExcel(ReportExcel{}, tbody, true) * if err != nil { * // * } * os.WriteFile("test.xlsx", buf.Bytes(), 0644) */.
GetDataHour 获取日期到小时 GetDataHour(time.Now()) return 2022122609.
GetDataHourRange 获取日期范围 GetDataHourRange(time.Unix(1672012800, 0), time.Unix(1672016400, 0)) ruturn []int{2022122608 2022122609}.
* * GetDateRange 获取日期范围,从零点开始 * * Example: * * startTime := time.Unix(1688870348, 0) // 2023-7-9 10:39:08 * endTime := time.Unix(1689059808, 0) // 2023-7-11 15:16:48 * * result := GetDateRange(startTime, endTime) * * for _, v := range result { * fmt.Println(v.Format("2006-01-02 15:04:05")) * //[ * // "2023-07-09 00:00:00", * // "2023-07-10 00:00:00", * // "2023-07-11 00:00:00", * //] * } */.
GetDtByOffset 获取日期 GetDtByOffset(time.Now(), 0) return 20060102.
GetMonthBounds 获取给定月份的第一天和最后一天 GetMonthBounds(202308) return 2023-08-01, 2023-08-31.
GetMonthByOffset 获取月份 GetMonthByOffset(time.Now(), 0) return 202308.
GetMonthRange 获取时间范围内的月份 GetMonthRange(time.Unix(1672016400, 0), time.Unix(1674694800, 0)) return [202212 202301].
* * GetTimeRangesByDay 按天划分时间范围,保留开始时间和结束时间 * * Example: * * startTime := time.Unix(1688870348, 0) // 2023-7-9 10:39:08 * endTime := time.Unix(1689059808, 0) // 2023-7-11 15:16:48 * * result := GetTimeRangesByDay(startTime, endTime) * * for _, v := range result { * fmt.Printf("startTime: %s, endTime: %s\n", v.StartTime.Format("2006-01-02 15:04:05"), v.EndTime.Format("2006-01-02 15:04:05")) * //[ * // ["2023-07-09 10:39:08", "2023-07-10 00:00:00"], * // ["2023-07-10 00:00:00", "2023-07-11 00:00:00"], * // ["2023-07-11 00:00:00", "2023-07-11 15:16:48"], * //] * } */.
GetWeekBounds 根据ISO周次获取特定周的第一天和最后一天 GetWeekBounds(202002) return 2020-01-06, 2020-01-12.
GetWeekByOffset 获取周次 GetWeekByOffset(time.Now(), 0) return 202301.
GetWeekRange 获取时间范围内的周次 GetWeekRange(time.Unix(1671790242, 0), time.Unix(1672588800, 0)) return []int{202251, 202252, 202301}.
InSlice 函数搜索数组中是否存在指定的值.
ParseTagSetting get model's field tags.
No description provided by the author
RandNum.
* * ReadExcelToStruct 读取excel到结构体 * * Example: * * type ReportExcel struct { * Dt string `excel:"日期"` * NewUsers int64 `excel:"注册人数"` * LoginUsers int64 `excel:"登录人数"` * Tmp int64 `excel:"-"` * } * * records, err := ReadExcelToStruct("test.xlsx", ReportExcel{}) * if err != nil { * // * } * fmt.Println(records) */.
SliceChunk 函数把一个数组分割为新的数组块.
SliceDiff 函数用于比较两个数组的值,并返回差集.
SliceShuffle 函数把数组中的元素按随机顺序重新排列.
SliceUnique 函数用于移除数组中重复的值.
SplitYearWeek 分割年和周次 SplitYearWeek(202301) return 2023, 01.
StartOfDay 获取指定日期零点时间.
StructDiff.

# Structs

No description provided by the author