mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал DateFromToToday_rus()
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ManyakRus/starter/constants"
|
||||
"github.com/dromara/carbon/v2"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/exp/constraints"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
@@ -32,6 +33,11 @@ import (
|
||||
|
||||
//var log = logger.GetLog()
|
||||
|
||||
func init() {
|
||||
//время всегда московское (из константы)
|
||||
carbon.SetLocation(constants.Loc)
|
||||
}
|
||||
|
||||
// IsTestApp - возвращает true если это тестовая среда выполнения приложения
|
||||
func IsTestApp() bool {
|
||||
Otvet := true
|
||||
@@ -1628,7 +1634,7 @@ func IsTrueString(s string) bool {
|
||||
|
||||
// DateTimeFromString_rus - возвращает дату из строки, из формата "02.01.2006 15:04:05"
|
||||
func DateTimeFromString_rus(s string) (time.Time, error) {
|
||||
t, err := time.Parse(constants.LayoutDateTimeRus, s)
|
||||
t, err := time.ParseInLocation(constants.LayoutDateTimeRus, s, constants.Loc)
|
||||
return t, err
|
||||
}
|
||||
|
||||
@@ -1641,6 +1647,15 @@ func DateFromString_rus(s string) (time.Time, error) {
|
||||
}
|
||||
|
||||
//
|
||||
t, err := time.Parse(constants.LayoutDateRus, s)
|
||||
t, err := time.ParseInLocation(constants.LayoutDateRus, s, constants.Loc)
|
||||
return t, err
|
||||
}
|
||||
|
||||
// DateFromToToday_rus - возвращает дату начала и конца дня
|
||||
func DateFromToToday_rus() (time.Time, time.Time) {
|
||||
//carbon.SetLocation(constants.Loc)
|
||||
Date1 := carbon.Now().StartOfDay().StdTime()
|
||||
Date2 := carbon.CreateFromStdTime(Date1).EndOfDay().StdTime()
|
||||
|
||||
return Date1, Date2
|
||||
}
|
||||
|
||||
@@ -1453,7 +1453,7 @@ func TestDateTimeFromString_rus(t *testing.T) {
|
||||
t.Errorf("Error: Expected nil, but got %v", err)
|
||||
}
|
||||
|
||||
TextGood := "2025-04-23 10:05:01 +0000 UTC"
|
||||
TextGood := "2025-04-23 10:05:01 +0300 MSK"
|
||||
if Otvet.String() != TextGood {
|
||||
t.Errorf("Expected '2025-04-23 10:05:01', but got %s", Otvet)
|
||||
}
|
||||
@@ -1467,8 +1467,15 @@ func TestDateFromString_rus(t *testing.T) {
|
||||
t.Errorf("Error: Expected nil, but got %v", err)
|
||||
}
|
||||
|
||||
TextGood := "2025-04-23 00:00:00 +0000 UTC"
|
||||
TextGood := "2025-04-23 00:00:00 +0300 MSK"
|
||||
if Otvet.String() != TextGood {
|
||||
t.Errorf("Expected '2025-04-23 00:00:00', but got %s", Otvet)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDateFromToToday_rus(t *testing.T) {
|
||||
DateFrom, DateTo := DateFromToToday_rus()
|
||||
if DateFrom == DateTo {
|
||||
t.Errorf("error: DateFrom == DateTo")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user