I am new to Youtrack Workflow. I am trying to create a new workflow for which I require hours from the current date-time.
I am using new Date().getHours() but it's not returning proper value.
say for example my current time is Fri Jun 12 2020 18:29:29 GMT+0530 (India Standard Time) then it should have got 18 as the current hour but, I am getting 12 as the current hour.
Also in the date-time function in Youtrack, there is no option for the same (https://www.jetbrains.com/help/youtrack/incloud/v1-date-time.html)
Please help me with this.
As of now, new Date().getHours( returns the time from the server Youtrack runs on. For example, if you run it on your own server (Standalone version), it returns the time set in your server's OS. If you run it on a Youtrack server (Incloud version), it returns the time set in our server's OS. If the server's OS fails to return the time, we fall back to the UTC time.
That's not a transparent behavior and is going to be addressed in this task in: https://youtrack.jetbrains.com/issue/JT-57972 In this task, we want to change it so that the time is returned based on your Youtrack settings. You can watch the issue to get notified of the changes made there. How to do it: https://take.ms/L0k8g (screenshot).
For now, though, if you use your own server, you can try to change the time there. Otherwise, I suggest that you get time in UTC using Date.getUTCHours() and then add constant hours to get your local time.
Related
Currently I am working on a project to create excel report when user clicks on Download Report Button from Application. Everything is working fine except the file name which is getting downloaded.
The problem is when we check from US (CST Time with Daylight Savings), suppose if user downloads the report at Nov 26, 9:00 pm, the file name is getting as Nov 27, 2020. We are using moment in node.js application for getting the time.
const date = moment().format('LL');
Can somebody knows where I am missing. If I am correct, the moment() function will return local time instead of UTC time. But seems to be getting UTC time instead of local time.
Do we need to use moment().local() instead?
Any help would be really appreciated.
Thanks in Advance.
I suppose you should pass a user timezone offset in URL:
// -300 - (CST with daylight savings)
https://somesite.com/api/report?offset=-300
And on a backend to change an offset with moment.js like this:
// old versions of a moment.js
const date = moment().zone(offset).format('LL')
// new versions of a moment.js
const date = moment().utcOffset(offset).format('LL')
I have a <input type="date"> field on my webpage and cannot understand why the value of this input changes when I send it via a HTTP POST request from the browser (using AngularJS) to the server (Java). Here is an example of what happens:
Date selected in browser via <input type="date">: Wed Jan 24 2018 00:00:00 GMT+1100 (AUS Eastern Daylight Time)
Date that appears on server when sent via POST request: 2018-01-23T13:00:00.000Z
It appears that, on the server-side, the value changes from the browser's timezone to UTC (in this case from Australia/Sydney to UTC).
How can I use <input type="date"> to just send the date portion of the value without having the timezones converted and dates messed up?
Failure
The Z on the end is short for Zulu and means UTC.
So 2018-01-24T00:00:00.000Z and 2018-01-23T13:00:00.000Z do not represent the same moment. They represent two different moments in history, two different points on the timeline, eleven hours apart.
If you are certain that pair of values were intended to be the same moment, then something went wrong. This is not an adjustment in time zone.
We cannot further diagnose the source of the error as we lack information.
What probably happens is your server converts it to it's local timezone.
Why it happens? To normalize your time.
Imagine situation where someone from UK sends date (for example 12am 2018.01.22), and then someone from US receives it, and it will show him exact same time, even if it's different time zone (different time for him).
What you want to do is to calculate timezones(webpage side), or if it's not something you want to achieve, try changing your servers time zone.
I am using new Date(<date-string>) and then .getTime() to pass date strings to milliseconds from 1970.
The problem is that the date strings does not contain the timezone on them. They are British, so the timezone will be GMT or GMT+1 depending on the date...
When I use this technique in the front-end (Chrome), or in the back-end (Node.js). The time zone taken is the British one (GMT or GMT+1 depending on the date). I assume that is taken from the OS.
However, when using a Node.js server which I have been told is configured to be in UTC... the timezone is always going to be GMT, leading to errors during the British Summer Time.
Is there any way to tell Date to take the timezone from the OS without changing the server configuration?
Example:
var aDate = new Date('2016-06-23 10:15:0');
var timestamp = aDate.getTime();
Just in case my explanation is not clear:
// Executed on 28-06-2016
// In the browser (in London)
new Date().getTimezoneOffset(); // -60
new Date('28-06-2016 11:11:11').getTimezoneOffset(); // -60
new Date('28-01-2016 11:11:11').getTimezoneOffset(); // 0
// In the Node.js server I am forced to use, which is configured to use UTC
new Date().getTimezoneOffset(); // 0
new Date('28-06-2016 11:11:11').getTimezoneOffset(); // 0
new Date('28-01-2016 11:11:11').getTimezoneOffset(); // 0
// Ideally, I would like to have the output I get in the browser when I run the code in the UTC Node.js server
I recommend using Moment Timezone for this, since this would be needlessly complicated to implement without a library. To get UTC in milliseconds from a given date in a given timezone, you can do this:
const moment = require('moment-timezone');
function londonTimeToUTC(dateString) {
return moment.tz(dateString, 'DD-MM-YYYY HH:mm:ss', 'Europe/London').valueOf();
}
console.log(londonTimeToUTC('28-06-2016 11:11:11')); // 1467108671000
console.log(londonTimeToUTC('28-01-2016 11:11:11')); // 1453979471000
The second argument passed to moment.tz() is a format string, which is necessary if the date string is not in ISO format. The third argument is any valid timezone identifier.
Is there any way to tell Date to take the timezone from the OS without changing the server configuration?
The time zone from the OS is what the Date object uses. If you're asking if you can change that time zone without changing the configuration, then no - there is not a way to do that. The Date object always takes on the behavior of the local time zone. Even if you supply an offset in the input string, it just uses that to determine the internal UTC timestamp. Output via most of the properties (including toString and getTimezoneOffset) will always use the local time zone.
Even in your examples, you cannot count on the browser behavior always returning the values you showed, simply because each user visiting your web site may have a different time zone setting.
The recommended way to deal with this is by using the moment.js library, which can handle UTC and local time by itself, but may require use of the moment-timezone extension if you are wanting to work with a specific time zone, such as Europe/London.
Now, with that said, if you're certain that your entire node.js application will run in a single time zone, and you're running on Linux or OSX (not Windows), then you can indeed change which time zone that node.js considers to be "local". Simply set the TZ environment variable before you launch node, like this:
env TZ='Europe/London' node server.js
There is no equivalent for the browser, or for Windows. And you still have to contend with possible non-UK users on your web site - so this doesn't guaranteed a match between client and server time. But it does address your question.
See also:
How to initialize javascript date to a particular timezone
How to make the timezone of date to UTC
How to set default timezone in Node.js
My app runs on Linux servers, where the time is (naturally) set to UTC/GMT. However the app is developed on Mac desktops where the time is typically set to a local timezone.
I could change every new Date() in my code to run:
var date = new Date().getTime();
And thus ensure dates on the server are always GMT, but that seems inelegant.
I understand previous versions of node used to always return UTC/GMT. Is there any way to bring this behavior back?
Edit: Removed adding timezone offset to getTime() per comments - since getTime() is already in UTC.
You can use TZ configuration parameter of node.js as follows.
For bash (and related)
export TZ=UTC
For Powershell
$env:TC = 'UTC'
Then for both:
nodejs server/index.js
From the MDN docs on Date#getTime:
The value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00 UTC.
Assuming you're storing dates/times as numbers (which I would recommend), getTime is already UTC, always.
Suppose your client then requests a date from the server. If the server provides the date as a number, the client can then do:
new Date(timestamp);
And it will be correctly adjusted to the local time on the client.
Of course, maybe I'm misunderstanding your problem. But I just want to point out that this...
new Date().getTime() + new Date().getTimezoneOffset();
...should never really make sense. It's taking a UTC-based time and then offsetting it further, in essence double-offsetting a time.
I need to find the time zone of the client machine using ASP.NET (C#) or JavaScript. What are the different time zones that are available all over the world and how to convert the date and time based on the users time zone.
Please provide some suggestions or sample coding to change the time based on the time zone.
You cannot find client time zone settings from ASP.NET.
You can use JavaScript to tell the current time, but there are several time zones that can be synchronized at any given time.
In Chrome, you can get the time zone from the JavaScript date object. There's no specific function for it, from what I've found, but the code
(new Date()).toString()
will yield something like
Mon Apr 18 2011 08:58:59 GMT+0200 (W. Europe Daylight Time)
In websites, the best approach I've found has been to have a setting for each user to specify the time zone to display all times in. If the JavaScript getUtcOffset gives a different offset than what is expected for the user's time zone, I'll show a notice for the user to review their settings. If time zone can be guessed from the date (which I've only found to be the case in chrome), I'll suggest that time zone, but I still resort to a select box for the user to manually pick the time zone.
Even so, it is possible to have the wrong time zone setting, without the script noticing it, because for a great part of the year, the two time zones may be perfectly synchronized.
Once you have a time zone (you can enumerate them all with System.TimeZoneInfo.GetSystemTimeZones()), you can convert UTC dates with System.TimeZoneInfo.ConvertTimeFromUtc and System.TimeZoneInfo.ConverTimeToUtc, respectively.