JSFiddle - React, Tailwind, and code Playground
HTML
<span id="time"></span>
JavaScript
function timestampToHellsinki(server_timestamp) {
function pad(num) {
num = num.toString();
if (num.length == 1) return "0" + num;
return num;
}
var _date = new Date();
_date.setTime(server_timestamp);
var _year = _date.getUTCFullYear();
// Because European Summer Time end date was made permanent
// in 1998, we cannot use this rule to dates before that
// and because the following calculation is valid until 2099
// as stated here http://www.webexhibits.org/daylightsaving/i.html,
// we have to return false if this function cannot calculate
// correct end and start dates.
// If other years have to covered, then they have to
// hardcode to this function, but covering years
// 1998 - 2099 is sufficient in most cases.
// To extend this function to cover other regions
// of Europe is easy, because DST start and end dates
// are the same, only need to change +2/+3 to something
// else. The above link has calculation rules to eg. USA.
if (_year<=1998 && _year>2099) return false;
// Calculate DST start day, it is the last sunday of March
var start_day = (31 - ((((5 * _year) / 4) + 4) % 7));
var SUMMER_start = new Date(Date.UTC(_year, 2, start_day, 1, 0, 0));
// Calculate DST end day, it is the last sunday of October
var end_day = (31 - ((((5 * _year) / 4) + 1) % 7))
var SUMMER_end = new Date(Date.UTC(_year, 9, end_day, 1, 0, 0));
// Check if the time is between SUMMER_start and SUMMER_end
// If the time is in summer, the offset is 2 hours
// else offset is 3 hours
var hellsinkiOffset = 2 * 60 * 60 * 1000;
if (_date > SUMMER_start && _date < SUMMER_end) hellsinkiOffset = 3 * 60 * 60 * 1000;
// Add server timestamp to midnight January 1, 1970
// Add Hellsinki offset to that
_date.setTime(server_timestamp + hellsinkiOffset);
var hellsinkiTime = pad(_date.getUTCDate()) + "." + pad(_date.getUTCMonth())...