1
0
mirror of https://github.com/ManyakRus/starter.git synced 2024-11-21 18:16:31 +02:00

сделал FindPreviousWorkDay()

This commit is contained in:
Nikitin Aleksandr 2024-03-05 09:59:37 +03:00
parent e052577f73
commit 86505e45e0
2 changed files with 30 additions and 5 deletions

View File

@ -10,22 +10,44 @@ import (
func FindPreviousWorkDay(DateNow time.Time) time.Time {
var Otvet time.Time
//DateNow := time.Now()
Otvet = carbon.CreateFromStdTime(DateNow).StartOfDay().ToStdTime()
CarbonDate := carbon.CreateFromStdTime(DateNow).StartOfDay()
Weekday := int(DateNow.Weekday())
switch Weekday {
case 0: //воскресенье
Otvet = carbon.CreateFromStdTime(Otvet).AddDays(-2).ToStdTime()
CarbonDate = CarbonDate.AddDays(-2)
case 1: //понедельник
Otvet = carbon.CreateFromStdTime(Otvet).AddDays(-3).ToStdTime()
CarbonDate = CarbonDate.AddDays(-3)
default:
Otvet = carbon.CreateFromStdTime(Otvet).AddDays(-1).ToStdTime()
CarbonDate = CarbonDate.AddDays(-1)
}
Otvet = CarbonDate.ToStdTime()
return Otvet
}
//// FindPreviousWorkDay - возвращает дату начала предыдущего рабочего(!) дня
//// доделать БД Postgres Календарь
//func FindPreviousWorkDay(DateNow time.Time) time.Time {
// var Otvet time.Time
//
// //DateNow := time.Now()
// Otvet = carbon.CreateFromStdTime(DateNow).StartOfDay().ToStdTime()
//
// Weekday := int(DateNow.Weekday())
// switch Weekday {
// case 0: //воскресенье
// Otvet = carbon.CreateFromStdTime(Otvet).AddDays(-2).ToStdTime()
// case 1: //понедельник
// Otvet = carbon.CreateFromStdTime(Otvet).AddDays(-3).ToStdTime()
// default:
// Otvet = carbon.CreateFromStdTime(Otvet).AddDays(-1).ToStdTime()
// }
//
// return Otvet
//}
func IsWorkDay(Date time.Time) bool {
Otvet := false

View File

@ -7,6 +7,7 @@ import (
"github.com/ManyakRus/starter/micro"
"github.com/joho/godotenv"
"os"
"strings"
//log "github.com/sirupsen/logrus"
//log "github.com/sirupsen/logrus"
//"gitlab.aescorp.ru/dsp_dev/notifier/notifier_adp_eml/internal/v0/app/types"
@ -31,6 +32,8 @@ func LoadEnvTest() {
//не загружаем для STAGE=dev, т.к. переменные окружения кубернетеса
stage := os.Getenv("STAGE")
stage = strings.ToLower(stage)
stage = strings.TrimSpace(stage)
if stage == "dev" || stage == "prod" {
log.Info("LoadEnv() ignore STAGE: dev, filename: ", filename)
return