File size: 700 Bytes
d834a80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package utils

import (
	"time"

	http_error "whatsapp-backend/models/error"

	"github.com/google/uuid"
)

func ToUUID(s any) (uuid.UUID, error) {
	sStr, ok := s.(string)
	if !ok {
		return uuid.UUID{}, http_error.INTERNAL_SERVER_ERROR
	}

	res, err := uuid.Parse(sStr)
	if err != nil {
		return uuid.UUID{}, http_error.INTERNAL_SERVER_ERROR
	}

	return res, nil
}
func CalculateRemainingTime(startTime, dueTime time.Time) int {
	now := time.Now()

	// kalau belum mulai (startTime > now), remaining = full duration
	if startTime.After(now) {
		return int(dueTime.Sub(startTime).Seconds())
	}

	remaining := int(dueTime.Sub(now).Seconds())

	if remaining < 0 {
		return 0
	}
	return remaining / 60
}