зеркало из https://github.com/softlandia/xlib.git
v0.1.4
This commit is contained in:
Родитель
1bdd59c103
Коммит
480a30cd55
5
HIST.md
5
HIST.md
|
@ -1,5 +1,10 @@
|
|||
# VERTION DESCRIPTION #
|
||||
|
||||
## ver 0.1.4 // 2021.01.23 ##
|
||||
|
||||
* update test with dayt & time
|
||||
* add Secret
|
||||
|
||||
## ver 0.1.3 // 2020.08.25 ##
|
||||
|
||||
* add AtoI
|
||||
|
|
21
README.md
21
README.md
|
@ -7,29 +7,32 @@
|
|||
|
||||
## functions ##
|
||||
|
||||
func AtoI(s stringm def int) int
|
||||
return int from string, on error return def
|
||||
func Secret(s string) string
|
||||
returns a string with the middle removed, "passport" -> "pa...rt"
|
||||
|
||||
func AtoI(s string, def int) int
|
||||
returns int from string, on error return def
|
||||
|
||||
func StrHash(s string) uint32
|
||||
return 32bit hash from string, using fnv.New32a
|
||||
returns 32bit hash from string, using fnv.New32a
|
||||
|
||||
func StrContainBackSlash(s string) bool
|
||||
return true if string s contain rune back slash '\'
|
||||
returns true if string s contain rune back slash '\'
|
||||
|
||||
func StrIsPrintRune(s string) bool
|
||||
return true if input string contain only of printable rune
|
||||
returns true if input string contain only of printable rune
|
||||
|
||||
func ChangeFileExt(iFileName, newExt string) string
|
||||
return file name with new extention
|
||||
returns file name with new extention
|
||||
|
||||
func FileExists(name string) bool
|
||||
return true if file exist
|
||||
returns true if file exist
|
||||
|
||||
func Max(x, y int) int
|
||||
return max from int
|
||||
returns max from int
|
||||
|
||||
func SortBytes(b []byte) []byte
|
||||
return sorted slice of byte
|
||||
returns sorted slice of byte
|
||||
|
||||
func SeekFileStop(fileName, strToSearch string) (int, *bufio.Scanner, error)
|
||||
search string in text file and return *bufio.Scanner at founded line
|
||||
|
|
4
date.go
4
date.go
|
@ -56,9 +56,7 @@ func Day(i int) time.Time {
|
|||
|
||||
// DayCount - количество дней в текущем году
|
||||
func DayCount() int {
|
||||
currentYear, _, _ := time.Now().Date()
|
||||
lastDay, _ := time.Parse("2006-01-02", fmt.Sprintf("%d-01-01", currentYear+1))
|
||||
return int(lastDay.Sub(FirstDay()).Hours() / 24)
|
||||
return Index(LastDay()) + 1
|
||||
}
|
||||
|
||||
// Yesterday - ровно на начало вчера
|
||||
|
|
|
@ -15,13 +15,13 @@ type tSortBytes = struct {
|
|||
}
|
||||
|
||||
var dSortBytes = []tSortBytes{
|
||||
tSortBytes{
|
||||
{
|
||||
[]byte{0, 'u', 'c', 'k'},
|
||||
[]byte{0, 'c', 'k', 'u'}},
|
||||
tSortBytes{
|
||||
{
|
||||
[]byte{0, 'c', 'k', 0},
|
||||
[]byte{0, 0, 'c', 'k'}},
|
||||
tSortBytes{
|
||||
{
|
||||
[]byte{'f', 'u', 'c', 'k', 'e', 'm', 'a', 'l', 'l'},
|
||||
[]byte{'a', 'c', 'e', 'f', 'k', 'l', 'l', 'm', 'u'}},
|
||||
}
|
||||
|
@ -35,41 +35,41 @@ func TestSortBytes(t *testing.T) {
|
|||
|
||||
func TestWeekDayR(t *testing.T) {
|
||||
tmp, _ := time.Parse("2006-01-02", "2020-01-01")
|
||||
assert.Equal(t, "Ср", WeekdayR(tmp))
|
||||
assert.Equal(t, "Ср", WeekdayR(tmp), WeekdayR(tmp))
|
||||
tmp, _ = time.Parse("2006-01-02", "2020-12-31")
|
||||
assert.Equal(t, "Чт", WeekdayR(tmp))
|
||||
assert.Equal(t, "Чт", WeekdayR(tmp), WeekdayR(tmp))
|
||||
tmp, _ = time.Parse("2006-01-02", "2020-08-30")
|
||||
assert.Equal(t, "Вс", WeekdayR(tmp))
|
||||
assert.Equal(t, "Вс", WeekdayR(tmp), WeekdayR(tmp))
|
||||
}
|
||||
|
||||
func TestDay(t *testing.T) {
|
||||
tmp, _ := time.Parse("2006-01-02", "2020-01-01")
|
||||
assert.Equal(t, tmp, Day(0))
|
||||
tmp, _ = time.Parse("2006-01-02", "2020-12-31")
|
||||
assert.Equal(t, tmp, Day(365))
|
||||
tmp, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
assert.Equal(t, tmp, Day(0), fmt.Sprintf("expect: %s, actual: %s", tmp.Format("2006-01-02"), Day(0).Format("2006-01-02")))
|
||||
tmp, _ = time.Parse("2006-01-02", "2021-12-31")
|
||||
assert.Equal(t, tmp, Day(364), Day(365).Format("2006-01-02"))
|
||||
}
|
||||
|
||||
func TestFirstDay(t *testing.T) {
|
||||
fd, _ := time.Parse("2006-01-02", "2020-01-01")
|
||||
fd, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
assert.Equal(t, fd, FirstDay())
|
||||
}
|
||||
|
||||
func TestLastDay(t *testing.T) {
|
||||
fd, _ := time.Parse("2006-01-02", "2020-12-31")
|
||||
fd, _ := time.Parse("2006-01-02", "2021-12-31")
|
||||
assert.Equal(t, fd, LastDay())
|
||||
}
|
||||
|
||||
func TestIndex(t *testing.T) {
|
||||
fd, _ := time.Parse("2006-01-02", "2020-01-01")
|
||||
fd, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
assert.Equal(t, 0, Index(fd))
|
||||
|
||||
fd, _ = time.Parse("2006-01-02", "2020-01-02")
|
||||
fd, _ = time.Parse("2006-01-02", "2021-01-02")
|
||||
assert.Equal(t, 1, Index(fd))
|
||||
|
||||
fd, _ = time.Parse("2006-01-02", "2020-12-31")
|
||||
assert.Equal(t, 365, Index(fd))
|
||||
fd, _ = time.Parse("2006-01-02", "2021-12-31")
|
||||
assert.Equal(t, 364, Index(fd))
|
||||
}
|
||||
|
||||
func TestDayCount(t *testing.T) {
|
||||
assert.Equal(t, 366, DayCount())
|
||||
assert.Equal(t, 365, DayCount(), DayCount())
|
||||
}
|
||||
|
|
|
@ -7,6 +7,14 @@ import (
|
|||
"unicode"
|
||||
)
|
||||
|
||||
// Secret - возвращает строку с вырезанной серединой, удобно для отображения токенов и паролей
|
||||
func Secret(s string) string {
|
||||
if len(s) < 4 {
|
||||
return s
|
||||
}
|
||||
return s[:2] + "..." + s[len(s)-2:]
|
||||
}
|
||||
|
||||
// AtoI - convert string to int, if error occure, return def value
|
||||
func AtoI(s string, def int) int {
|
||||
n, err := strconv.ParseInt(s, 10, 64)
|
||||
|
|
|
@ -58,7 +58,7 @@ type testpairStrIsPrintRune struct {
|
|||
|
||||
var testsStrIsPrintRune = []testpairStrIsPrintRune{
|
||||
{"consist printable rune \\", true},
|
||||
{"consist non" + string(0x00) + "printable rune", false},
|
||||
{"consist non" + "\x00" + "printable rune", false},
|
||||
}
|
||||
|
||||
func TestStrIsPrintRune(t *testing.T) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче