Исправлена логика переноса задач с учётом часового пояса
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 56s

This commit is contained in:
poignatov
2026-01-19 22:06:46 +03:00
parent cd61fe4766
commit be2ae80226
3 changed files with 54 additions and 9 deletions

View File

@@ -1 +1 @@
3.14.9
3.14.10

View File

@@ -7550,7 +7550,16 @@ func (a *App) createTaskHandler(w http.ResponseWriter, r *http.Request) {
var insertArgs []interface{}
if repetitionPeriod.Valid {
// Для 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 = `
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)
@@ -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}
} else if repetitionDate.Valid {
// Вычисляем 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 {
insertSQL = `
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 значений
var updateSQL string
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 {
// Для repetition_period выставляем сегодняшнюю дату
now := time.Now()
now := time.Now().In(loc)
updateSQL = `
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
@@ -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}
} else if repetitionDate.Valid {
// Вычисляем next_show_at для задачи с repetition_date
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now().In(loc))
if nextShowAt != nil {
updateSQL = `
UPDATE tasks
@@ -8676,7 +8703,16 @@ func (a *App) completeTaskHandler(w http.ResponseWriter, r *http.Request) {
if hasRepetitionDate {
// Есть 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 {
_, err = a.DB.Exec(`
UPDATE tasks
@@ -8707,8 +8743,17 @@ func (a *App) completeTaskHandler(w http.ResponseWriter, r *http.Request) {
} else {
// Обычный период: обновляем счетчик и last_completed_at, вычисляем next_show_at
// 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)
if nextShowAt != nil {
log.Printf("Calculated next_show_at for task %d: %v", taskID, *nextShowAt)

View File

@@ -1,6 +1,6 @@
{
"name": "play-life-web",
"version": "3.14.9",
"version": "3.14.10",
"type": "module",
"scripts": {
"dev": "vite",