You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
983 B

  1. package Helper
  2. import (
  3. "strconv"
  4. "strings"
  5. "time"
  6. )
  7. func MinusInt64(a, b int64) string {
  8. return strconv.FormatInt(a-b, 10)
  9. }
  10. func MinusInt(a, b int) string {
  11. return strconv.Itoa(a - b)
  12. }
  13. func Minus(a, b int) int {
  14. return a - b
  15. }
  16. func PlusInt64(a, b int64) string {
  17. return strconv.FormatInt(a+b, 10)
  18. }
  19. func PlusInt(a, b int) string {
  20. return strconv.Itoa(a + b)
  21. }
  22. func Iterate(count int) []int {
  23. var i int
  24. var Items []int
  25. for i = 0; i < count; i++ {
  26. Items = append(Items, i)
  27. }
  28. return Items
  29. }
  30. func StrToLower(s string) string {
  31. return strings.ToLower(s)
  32. }
  33. func FormatTimestamp(t interface{}) string {
  34. var (
  35. s string
  36. tt time.Time
  37. exists bool
  38. )
  39. // Check if timestamp is string
  40. s, exists = t.(string)
  41. if exists {
  42. return s
  43. }
  44. // Check if timestamp is time.Time
  45. tt, exists = t.(time.Time)
  46. if !exists || tt.IsZero() {
  47. return ""
  48. }
  49. loc, _ := time.LoadLocation("Australia/Adelaide")
  50. return tt.
  51. In(loc).
  52. Format("02/01/2006 03:04 PM")
  53. }