Look the start_time
field. It changed from what I posted. What I want is, the stored data is same as what I posted from Postman.
I found that the issue happens because of the timezone obviously. So I just need to take care of the timezone. That was my first thought. I think my systems have a bug about this.
To fix this issue, I’m doing all this action below.
Because I’m using the MySQL as my DB storage, so I need a driver to connect my application with the MySQL. I’m using github.com/go-sql-driver/mysql as my connection driver. So after looking for the documentation and checking my connection string, nothing wrong happen. I made it correctly.
dsn := root:root@tcp(127.0.0.1:3306)/event?parseTime=true&loc=Asia%2FJakarta&charset=utf8mb4&collation=utf8mb4_unicode_ci
Still curious, why this is happening. Then I’m trying to find any Q/A or Issue about this in StackOverflow or even in GitHub.
To be honest, it takes up to 2 hours for me when trying to fix this issue 🤦Until then, I got frustrated. So I have 2 option how to solve this.
start_time
before stored to Database.But, just want to give more effort 😶, I made the fix with rebuilding the DateTime.
startTime := e.StartTime
loc, _ := time.LoadLocation("Asia/Jakarta")
localStartTime := time.Date(startTime.Year(), startTime.Month(), startTime.Day(), startTime.Hour(), startTime.Minute(), startTime.Second(), startTime.Nanosecond(), loc)
Then, just out of curiosity, I ask my team about the issue. Then they look how I reproduce it, same as me, they also curious why this is happening. Until just a few minutes, one of my team found the reasons why this is happening.
This is happening because I made a wrong timezone offset in my request body.
{"title": "Core i13 Anniversarry","place": "Ancol Beach","start_time": "2018-09-22T12:42:31Z" // look for the `Z` indicator}
Because I lived in +7.00 timezone (Asia/Jakarta)
, it should be included in my JSON.
So, when I change the start_time
from:
2018-09-22T12:42:31Z
into
2018-09-22T12:42:31**+07:00**
it solves my problem. Nothing wrong happened to my system. All is work perfectly.
When I realized this, I feel so dumb 🤦. I’ve spent my two hours of my life for nothing 🤦.
2018–09–22T12:42:31+07:00
is the RFC 3339 format, every single character is matter.If you think this article is worth to read, give a clap or share to your network circle, so everyone can also read this. Follow for more stories like this!