NexsterOrg / nexster

Runtime of all micro services for the Nexster social network.
https://community.nexster.xyz
Other
0 stars 0 forks source link

Time difference issue between systems #12

Closed NamalSanjaya closed 9 months ago

NamalSanjaya commented 1 year ago

front end and back end usually run on different places. There fore they have different time values. In distributed systems even in multiple back-end systems they have different time values. This issue need a long term solution. Here are few suggestions

NamalSanjaya commented 1 year ago

Ask location info from brower

// Check if the browser supports Geolocation
if (navigator.geolocation) {
  // Request the current position
  navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
} else {
  console.log("Geolocation is not supported by this browser.");
}

// Success callback function
function successCallback(position) {
  var latitude = position.coords.latitude;
  var longitude = position.coords.longitude;

  console.log("Latitude: " + latitude);
  console.log("Longitude: " + longitude);

  // Make use of latitude and longitude to get the location information using external APIs or services
}

// Error callback function
function errorCallback(error) {
  console.log("Error getting location: " + error.message);
}
NamalSanjaya commented 1 year ago

How to get time based on the location

// Create a new Date object
var date = new Date();

// Get the current date and time in Sri Lankan format
var options = { timeZone: 'Asia/Colombo', hour12: false };
var sriLankanDateTime = date.toLocaleString('en-LK', options);
var utcTime = date.toLocaleString('en-US', { timeZone: 'UTC' });

console.log(sriLankanDateTime, utcTime);
NamalSanjaya commented 1 year ago

Import

Once this problem solved, we need to change all places in our nexster project related to time.

NamalSanjaya commented 1 year ago

Solution

In backend we use UTC time zone with no offset. which means our all the time related information store in database store for UTC-0.

Therefore all outgoing API request need to have additional data to figure out the offset of respective location.