highchart changes to UTC in jasperserver - highcharts

I design a highchart using jaspersoft studio and then deploy it to the server.
The time value in x axis is local time and it is fine in jaspersoft studio. But when I deploy it to jasperserver, the values comes up in UTC again.
If I just display the values in grids (not chart), the values are displayed in local time so all fine. But with the highchart, the problem emerges..
Can you help me with that

I solved that problem a while ago. I post my solution for the others who may face it.
JasperServer also makes a timezone conversation within itself whereas jasperSoft Studio does not as expected. That creates the contradiction..
Since Jasperserver makes the conversion automatically, I used the REPORT_TIMEZONE parameter to get the server's timezone and made the calculation of local time considering the conversion.

You can disable UTC in highcharts by option:
Highcharts.setOptions({
global: {
useUTC: false
}
});
Docs: http://api.highcharts.com/highcharts#global.useUTC

Related

fullcalendar - Set current date based on timezone

There have been a couple of similar questions in the past, but none I've found have been fully answered so let me try again.
I'm writing this web app where users can select their particular timezone, which might be different from the one set up in their respective system. Say my computer is set to the "America/New_York" timezone. If I (for whatever reason) set up my timezone configuration to "Asia/Tokyo" within the web app, I would like to:
have the current month aligned with the configured timezone ("Asia/Tokyo") and
have the highlighted current date also set to the "Asia/Tokyo" timezone.
I've tried many different configurations without any luck...
$("#calendar").fullCalendar({
defaultView: "month",
timezone: "Asia/Tokyo",
ignoreTimezone: false,
defaultDate: moment("2019-03-10"),
header: {...
In this case, I'm hard coding the defaultDate for tomorrow ("2019-03-10") to see if the current date highlight changes to no avail.
Is there a way to accomplish these two issues?
Update:
Okay, the answer to question (2) I found to be the parameter now. In this case, things would look like...
$("#calendar").fullCalendar({ defaultView: "month", now: moment().tz("Asia/Tokyo"), ...
As explained above, if say, my laptop is said to be configured with the "America/New_York" timezone, but I'm actually in Japan and my web app config reflects that, it won't matter. fullCalendar will now show the correct day for Today.
Still, the question remaining is (1): How to make the (monthly) calendar days be in sync with a given timezone? Thanks!

Ical.Net: Event's AsUtc flag is not updating correctly

I am facing this issue in Ical.Net Version=4.0.1.0 and lower, When we get "GMT-0500" in DTSTART/DTEND then it is giving same utc time as local time in AsUtc. But If I replace "GMT-0500" to "Canada/Eastern" manually in ics its giving correct utc time in AsUtc.
Following is not working fine -:
DTSTART;TZID=GMT-0500:20181213T190000
DTEND;TZID=GMT-0500:20181213T220000
Following works fine -:
DTSTART;TZID=Canada/Eastern:20181213T190000
DTEND;TZID=Canada/Eastern:20181213T220000
GMT-0500 isn't a valid IANA time zone. Here's the list of IANA time zones. You want Etc/GMT+5.
Canada/Eastern is deprecated. I suggest you use America/Toronto instead.
In general, I suggest you familiarize yourself with the actual time zone names instead of guessing as to what they might be, and hoping for the best.
There were also some bugs with caching AsUtc values, as I noted in the release notes. I suggest upgrading to 4.latest. It should be backwards compatible.

ToLocalTime shows wrong time

I am running a website in IIS on my local PC, I save a date as UTC and call .ToLocalTime() on it in the front end mvc website. If I run the website on my local PC it outputs the correct date and time adjusted for DST. If I run it in Azure in region UK West I get 1 hour behind. This hasn't been an issue until today i.e. the clocks changed on Saturday. Do I need to raise a ticket with Azure? Or am I doing it wrong?
Azure App server is using UTC time. If your site is not global just for UK. We can use the following code to get the UK local time.
DateTime utcNow = DateTime.UtcNow;
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); //UK time zone
DateTimeOffset time = TimeZoneInfo.ConvertTimeFromUtc(utcNow, tz);
lab_time.Text = time.DateTime.ToString(CultureInfo.InvariantCulture); //display the datetime with label.
If your website is to be global that you may need to use javascrpt to do that, more detail please refer to another SO Thread.
Time-zone depends on the the server location literally.
I had faced the same issue. I had my server in Singapore and it used to clash with my zone, India.
It would affect the time and date formats too.
So, Better not use the ToLocalTime() at the server side. just get the UTC time from the server and convert to whatever local time at the client side. Issue resolved!
Hope this helps. Thank you.

Converting UTC to local Timezone in Azure WebRole

Quick environment overview:
I have an ASP.NET MVC/AngularJS application that is ultimately being hosted as an Azure Webrole. The data is stored in MongoDB hosted in the same Azure data center (via MongoLab). Development environment and staging environment (Azure) point to same MongoDB database and thus see the exact same data.
Issue:
Individual users of the application are stored with their preferred timezone as a string (TimezoneID). All dates in the app are stored as UTC times. Conversion to and from UTC times to a users specific timezone is done on the server via an extension method which ultimately calls:
return TimeZoneInfo.ConvertTimeFromUtc(UtcDate, _lookup[TimeZoneID]);
Nowhere in the entire app is there a DateTime.Now or any other date conversion I would expect to use the server time settings.
In a particular area of the application a date is being stored in Mongo (UTC). I can confirm that the date is correctly stored as UTC (based on the offset from my local time). When I retrieve that date from the data store and convert it back to my local time (Central Standard Time) I step over the above line of code and the conversion works fine and the local time is set. The result is sent to the client's browser as part of a Json result of an API call and displayed to the user correctly. During transport the MVC Json serializer parses the datetime into a format similar to:
EventDate: "/Date(1399407153971)/"
I parse this in Javascript and display accordingly and all is good.
When I deploy the exact same code to Azure (which points to the exact same data store in Mongo) the result that comes down via the API call appears to have applied the UTC transformation twice (meaning the regular 6 hour UTC offset is applied twice and the displayed date is 12 hours earlier than UTC...6 hours off of what I want).
I've updated the stored time in Mongo by a minute or two to make sure both sides update and they do (verifying the same data). I've modified the date/time settings of my local machine to see if it has any effect on my local results and it does not. I've changed the timezone for the selected user in the app and both my local result AND the Azure returned result adjust by the UTC offset difference between Central Standard Time and the new time zone (meaning if I switch to Mountain Time the result of both the local result and the Azure result adjust by 1 hour...but are still 6 hours off). I've confirmed via Chrome Dev Tools that the date in question that is retrieved at the client (via Json) is different based on whether the site hit was the remove (Azure) environment or local environment (meaning it isn't being modified incorrectly anywhere on the client after-the-fact)
Here is the most telling thing:
If I convert the date to a string prior to returning it to the client the string sent down appears correct in the Json response. If I leave it as a .NET DateTime type (as a property of a complex object) the Json serializer appears to translate it again but ONLY when hosted in Azure. This has pointed me to the issue being somehow related to the DateTimeKind of the date I'm returning. Although, at this point, I'm too lost in the weeks to see why the difference between my local environment and the Azure host environment in serialization and why one things a time is correct and the other converts it twice. If the DateKindTime was wrong wouldn't both environments perform the same conversion?
Thanks for reading through this and I'd appreciate any ideas to address anyone has.
It's difficult to say for sure without seeing more code, but could it be that the problem is with conversion on the way in, rather than on the way out? You said that you're using TimeZoneInfo.ConvertTimeFromUtc for the output. Are you also using TimeZoneInfo.ConvertTimeToUtc on the other side? If so, that's likely the source of picking up your local time zone.
You might also somewhere have a call to DateTime.ToUniversalTime, which again - uses the local time zone.
Another area which might be the culprit - when you retrieve your value from Mongo, check the Kind of the values coming back. If they're Unspecified, then when they are serialized to JSON, they will be treated as if they were Local. basically, there's a ToUniversalTime call going on under the hood. So you may need to explicitly call DateTime.SpecifyKind to set the value to Utc before it goes out the door.
With specific regards to Azure, it follows best practices of setting the server time zone to UTC. You could try that on your own machine and see if you get similar results.
Of course, you really don't want the server's time zone to influence the result at all.
You may want to consider creating a new project with a minimal, complete, and verifiable example. That will help you verify your assumptions, and will likely track down the source of the problem. If it still fails, well then you'll be in much better shape for asking for help.
That was a long post :)
If I were you I would transfer all dateTimes in UTC format. The server basically must work with UTC time as far as I'm concerned. Transformation to client time must be applied at clients side. You can use momentjs library that proved to be very fine library for working with dates and times.
On client side do something like this
var date = {
utc: '/Date(1399407153971)/', //time that you have recieved
offset: 240
}
var localTime = moment.utc(date.utc).zone(date.offset).format('DD/MM/YYYY hh:mm');
I hope this helps
UPD
As Matt Johnson pointed out you can make it even shorter for current time zone.
var localTime = moment('/Date(1399407153971)/').format('DD/MM/YYYY hh:mm');

how I can have two clocks on my page and they will be updating in real time?

I have a weather website and I'm driving me crazy to figure out how I can have two clocks on my page and they will be updating in real time. One with the 'Europe/Lisbon' timezone and the and the other with the 'UTC' timezone
Now I have this code lines:
<strong>Elvas:</strong>
<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('Europe/Lisbon');
// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('H:i');
?>
&nbsp &nbsp
<strong>UTC:</strong>
<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('UTC');
// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('H:i');
?>
But of course with no automatic updates as I would like.
Thanks in advance for any posible help you could give to me.
PHP is a server-side technology. If you want to update your page in real-time, you need to stick with JavaScript.
By default, JavaScript doesn't know anything about time zones, other than the time zone of the computer it is running on. In order to display the time in some other time zone, you will need a time zone database for JavaScript. I list several of them here.
For example, you can use moment.js with the moment-timezone add-on. Getting the current time in a specific time zone is like this:
moment().tz('Europe/Lisbon').format('YYYY-MM-DD HH:mm:ss')
To update it periodically, you can use window.setInterval.
If you are looking for a very easy solution already coded for you, consider using the "Free Clocks for Your Website" offered at timeanddate.com. They are very reliable and customizable for different time zones.

Resources