Исправлена логика переноса задач с учётом часового пояса
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 56s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 56s
This commit is contained in:
@@ -7550,7 +7550,16 @@ func (a *App) createTaskHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
var insertArgs []interface{}
|
var insertArgs []interface{}
|
||||||
if repetitionPeriod.Valid {
|
if repetitionPeriod.Valid {
|
||||||
// Для repetition_period выставляем сегодняшнюю дату
|
// Для repetition_period выставляем сегодняшнюю дату
|
||||||
now := time.Now()
|
|
||||||
|
// Получаем часовой пояс из переменной окружения (по умолчанию UTC)
|
||||||
|
timezoneStr := getEnv("TIMEZONE", "UTC")
|
||||||
|
loc, err := time.LoadLocation(timezoneStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: Invalid timezone '%s': %v. Using UTC instead.", timezoneStr, err)
|
||||||
|
loc = time.UTC
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now().In(loc)
|
||||||
insertSQL = `
|
insertSQL = `
|
||||||
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, next_show_at, completed, deleted, wishlist_id, reward_policy)
|
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, next_show_at, completed, deleted, wishlist_id, reward_policy)
|
||||||
VALUES ($1, $2, $3, $4, $5::INTERVAL, NULL, $6, 0, FALSE, $7, $8)
|
VALUES ($1, $2, $3, $4, $5::INTERVAL, NULL, $6, 0, FALSE, $7, $8)
|
||||||
@@ -7559,7 +7568,16 @@ func (a *App) createTaskHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
insertArgs = []interface{}{userID, strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriodValue, now, wishlistIDValue, rewardPolicyValue}
|
insertArgs = []interface{}{userID, strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriodValue, now, wishlistIDValue, rewardPolicyValue}
|
||||||
} else if repetitionDate.Valid {
|
} else if repetitionDate.Valid {
|
||||||
// Вычисляем next_show_at для задачи с repetition_date
|
// Вычисляем next_show_at для задачи с repetition_date
|
||||||
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
|
|
||||||
|
// Получаем часовой пояс из переменной окружения (по умолчанию UTC)
|
||||||
|
timezoneStr := getEnv("TIMEZONE", "UTC")
|
||||||
|
loc, err := time.LoadLocation(timezoneStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: Invalid timezone '%s': %v. Using UTC instead.", timezoneStr, err)
|
||||||
|
loc = time.UTC
|
||||||
|
}
|
||||||
|
|
||||||
|
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now().In(loc))
|
||||||
if nextShowAt != nil {
|
if nextShowAt != nil {
|
||||||
insertSQL = `
|
insertSQL = `
|
||||||
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, next_show_at, completed, deleted, wishlist_id, reward_policy)
|
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, next_show_at, completed, deleted, wishlist_id, reward_policy)
|
||||||
@@ -7933,9 +7951,18 @@ func (a *App) updateTaskHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Используем условный SQL для обработки NULL значений
|
// Используем условный SQL для обработки NULL значений
|
||||||
var updateSQL string
|
var updateSQL string
|
||||||
var updateArgs []interface{}
|
var updateArgs []interface{}
|
||||||
|
|
||||||
|
// Получаем часовой пояс из переменной окружения (по умолчанию UTC)
|
||||||
|
timezoneStr := getEnv("TIMEZONE", "UTC")
|
||||||
|
loc, err := time.LoadLocation(timezoneStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: Invalid timezone '%s': %v. Using UTC instead.", timezoneStr, err)
|
||||||
|
loc = time.UTC
|
||||||
|
}
|
||||||
|
|
||||||
if repetitionPeriod.Valid {
|
if repetitionPeriod.Valid {
|
||||||
// Для repetition_period выставляем сегодняшнюю дату
|
// Для repetition_period выставляем сегодняшнюю дату
|
||||||
now := time.Now()
|
now := time.Now().In(loc)
|
||||||
updateSQL = `
|
updateSQL = `
|
||||||
UPDATE tasks
|
UPDATE tasks
|
||||||
SET name = $1, reward_message = $2, progression_base = $3, repetition_period = $4::INTERVAL, repetition_date = NULL, next_show_at = $5, wishlist_id = $6, reward_policy = $7
|
SET name = $1, reward_message = $2, progression_base = $3, repetition_period = $4::INTERVAL, repetition_date = NULL, next_show_at = $5, wishlist_id = $6, reward_policy = $7
|
||||||
@@ -7944,7 +7971,7 @@ func (a *App) updateTaskHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
updateArgs = []interface{}{strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriod.String, now, newWishlistID, rewardPolicyValue, taskID}
|
updateArgs = []interface{}{strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriod.String, now, newWishlistID, rewardPolicyValue, taskID}
|
||||||
} else if repetitionDate.Valid {
|
} else if repetitionDate.Valid {
|
||||||
// Вычисляем next_show_at для задачи с repetition_date
|
// Вычисляем next_show_at для задачи с repetition_date
|
||||||
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
|
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now().In(loc))
|
||||||
if nextShowAt != nil {
|
if nextShowAt != nil {
|
||||||
updateSQL = `
|
updateSQL = `
|
||||||
UPDATE tasks
|
UPDATE tasks
|
||||||
@@ -8676,7 +8703,16 @@ func (a *App) completeTaskHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if hasRepetitionDate {
|
if hasRepetitionDate {
|
||||||
// Есть repetition_date - вычисляем следующую дату показа
|
// Есть repetition_date - вычисляем следующую дату показа
|
||||||
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
|
|
||||||
|
// Получаем часовой пояс из переменной окружения (по умолчанию UTC)
|
||||||
|
timezoneStr := getEnv("TIMEZONE", "UTC")
|
||||||
|
loc, err := time.LoadLocation(timezoneStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: Invalid timezone '%s': %v. Using UTC instead.", timezoneStr, err)
|
||||||
|
loc = time.UTC
|
||||||
|
}
|
||||||
|
|
||||||
|
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now().In(loc))
|
||||||
if nextShowAt != nil {
|
if nextShowAt != nil {
|
||||||
_, err = a.DB.Exec(`
|
_, err = a.DB.Exec(`
|
||||||
UPDATE tasks
|
UPDATE tasks
|
||||||
@@ -8707,8 +8743,17 @@ func (a *App) completeTaskHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
// Обычный период: обновляем счетчик и last_completed_at, вычисляем next_show_at
|
// Обычный период: обновляем счетчик и last_completed_at, вычисляем next_show_at
|
||||||
// next_show_at = last_completed_at + repetition_period
|
// next_show_at = last_completed_at + repetition_period
|
||||||
now := time.Now()
|
|
||||||
log.Printf("Calculating next_show_at for task %d: repetition_period='%s', fromDate=%v", taskID, repetitionPeriod.String, now)
|
// Получаем часовой пояс из переменной окружения (по умолчанию UTC)
|
||||||
|
timezoneStr := getEnv("TIMEZONE", "UTC")
|
||||||
|
loc, err := time.LoadLocation(timezoneStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: Invalid timezone '%s': %v. Using UTC instead.", timezoneStr, err)
|
||||||
|
loc = time.UTC
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now().In(loc)
|
||||||
|
log.Printf("Calculating next_show_at for task %d: repetition_period='%s', fromDate=%v (timezone: %s)", taskID, repetitionPeriod.String, now, timezoneStr)
|
||||||
nextShowAt := calculateNextShowAtFromRepetitionPeriod(repetitionPeriod.String, now)
|
nextShowAt := calculateNextShowAtFromRepetitionPeriod(repetitionPeriod.String, now)
|
||||||
if nextShowAt != nil {
|
if nextShowAt != nil {
|
||||||
log.Printf("Calculated next_show_at for task %d: %v", taskID, *nextShowAt)
|
log.Printf("Calculated next_show_at for task %d: %v", taskID, *nextShowAt)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "play-life-web",
|
"name": "play-life-web",
|
||||||
"version": "3.14.9",
|
"version": "3.14.10",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
Reference in New Issue
Block a user