-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmts.go
92 lines (70 loc) · 1.65 KB
/
fmts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package fmts
import (
"bytes"
"io"
"log"
"math"
"os"
"strings"
"time"
gcat "github.com/jeffotoni/gconcat"
)
// Stdout func
func Stdout(strs ...interface{}) {
str := gcat.Build(strs...)
_, err := io.Copy(os.Stdout, strings.NewReader(str))
if err != nil {
log.Println(err)
}
}
// Concat
func Concat(strs ...interface{}) string {
return gcat.Concat(strs...)
}
// ConcatStr
func ConcatStr(strs ...string) string {
return gcat.ConcatStr(strs...)
}
// ConcatStr
func ConcatStrInt(strs ...interface{}) string {
return gcat.ConcatStringInt(strs...)
}
// substr (text, 2, 30)
func Substr(value string, leni, lenf int) string {
if len(value) < leni {
return ""
}
lenx := len(value) // max of text
leny := lenf // amount of character
if lenx < lenf { // amount of character
leny = lenx
}
// return..
return value[leni:leny]
}
// replaces "\t" and "\n" to ""
func ReplaceSpaces(b *[]byte) {
*b = bytes.ReplaceAll(*b, []byte("\t"), []byte(""))
*b = bytes.ReplaceAll(*b, []byte("\n"), []byte(""))
}
/*
CalculateDaysDate - This function returns number of days of difference between two dates;
Case returns: -(some number) // it's before start date;
Case returns: (some number) // it's after start date;
*/
func CalculateDaysDate(initialDate, fDate string, layout string) (int, error) {
startDate, err := time.Parse(layout, initialDate)
if err != nil {
return 0, err
}
finalDate, err := time.Parse(layout, fDate)
if err != nil {
return 0, err
}
duration := startDate.Sub(finalDate)
durationDays := math.Abs(duration.Hours() / 24)
if finalDate.After(startDate) {
return int(durationDays), nil
}
return -int(durationDays), nil
}