mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-29 23:38:14 +02:00
сделал DateTimeFromString_rus()
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ManyakRus/starter/constants"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
@@ -1624,3 +1625,22 @@ func IsTrueString(s string) bool {
|
|||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DateTimeFromString_rus - возвращает дату из строки, из формата "02.01.2006 15:04:05"
|
||||||
|
func DateTimeFromString_rus(s string) (time.Time, error) {
|
||||||
|
t, err := time.Parse(constants.LayoutDateTimeRus, s)
|
||||||
|
return t, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateFromString_rus - возвращает дату из строки, из формата "02.01.2006"
|
||||||
|
func DateFromString_rus(s string) (time.Time, error) {
|
||||||
|
|
||||||
|
//
|
||||||
|
if len(s) > 10 {
|
||||||
|
s = s[:10]
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
t, err := time.Parse(constants.LayoutDateRus, s)
|
||||||
|
return t, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1444,3 +1444,31 @@ func TestStringFromFloat32_Dimension(t *testing.T) {
|
|||||||
t.Errorf("Expected '1', but got %s", Otvet)
|
t.Errorf("Expected '1', but got %s", Otvet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDateTimeFromString_rus(t *testing.T) {
|
||||||
|
Text := "23.04.2025 10:05:01"
|
||||||
|
|
||||||
|
Otvet, err := DateTimeFromString_rus(Text)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error: Expected nil, but got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
TextGood := "2025-04-23 10:05:01 +0000 UTC"
|
||||||
|
if Otvet.String() != TextGood {
|
||||||
|
t.Errorf("Expected '2025-04-23 10:05:01', but got %s", Otvet)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDateFromString_rus(t *testing.T) {
|
||||||
|
Text := "23.04.2025 10:05:01"
|
||||||
|
|
||||||
|
Otvet, err := DateFromString_rus(Text)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error: Expected nil, but got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
TextGood := "2025-04-23 00:00:00 +0000 UTC"
|
||||||
|
if Otvet.String() != TextGood {
|
||||||
|
t.Errorf("Expected '2025-04-23 00:00:00', but got %s", Otvet)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user