Convert Jira's time tracking field format to hours - ruby

I am using JIRA api to extract timespent by users on issues. The time spent is in the format:
"12w 1d 2h 5m" or "12h" or "12m" etc
The API isn't exporting the number of hours.
Is there a quick (requires no effort on my part) way to convert this to hours (or seconds). I suppose this is some sort of a standard format, is there a name for it?
I know how to do this myself, just don't want to reinvent the wheel

The chronic_duration gem can parse that into seconds:
ChronicDuration.parse("12w 1d 2h 5m") # => 7351500
As far as I know that format isn't a standard. ISO 8601 does include a format for durations, but that ain't it.

Take a look at JiraDurationUtils. It will use the Time Tracking configuration to convert properly.

Related

Convert Apple Cocoa Core Data timestamp in Excel

I'm trying to convert the Cocoa timestamps to human-readable dates with time. For context, these numbers are coming from the history.db file within ~/Library/ for Safari. I can convert individual numbers with the awesome tool at epochconverter.com, but they do not offer a batch converter for Cocoa.
As an example, 638490901.575263 should convert to Friday, March 26, 2021 3:35:01 PM GMT-07:00. In Excel, I'm using:
=("cell reference"/86400000) + DATE(2001,1,1), but getting 1/8/01 9:21 AM. Looks like I need to add time for the Cocoa Epoch delta, but unsure how to do that.
Thanks for any help!
You have too many 0 in the formula, the number is the number of seconds since the start of 1/1/2001. There are 86400 seconds in a day. Then add the start date so we get the correct number of dates from 12/31/1899 which is what Excel uses. Then we need to subtract 7 hours to get the correct time zone difference.
=(A1/86400) + DATE(2001,1,1) - TIME(7,0,0)

Working with datetime in Elixir

I need to find a difference in minutes between the time from a database retrieved by Ecto and current time, in UTC. As far as I know, timing operating on Elixir aren't trivial without using third-party libraries such as Timex. I, however, want to avoid using third-party dependencies. So how can I find a time difference? I know I can get the current time by DateTime.utc_now(), but what's next, how to subtract a date-time from a database, which is in Ecto.DateTime format, from it?
I believe there are plans soon for Ecto to use the native Elixir Datetime format for the time being, I know your pain.
One solution is to convert the ecto date time to the erlang date time format:
{{YYYY, MM, DD}, {HH, MM, SS}}
And then compare that using the erlang calendar library. For example, say we had a Post model and we wanted to know how long ago it was updated:
Repo.Post.get!(%Post{}, 1).created_at
|> Ecto.DateTime.to_erl
|> :calendar.time_difference(:calendar.universal_time)
So let's say this post was created roughly 1 month ago (2016-10-25T10:24:23).
Running it through the above function would return:
{30, {17, 30, 53}}
Meaning 30 days, 17 hours, 30 minutes and 53 seconds ago.
You can easily from there destructure the tuple and take only the components you need (in your case the minutes).
E.g.
{_, {_h, minutes, _s}} = time_diff

Language independent way of checking timezone in powershell?

I'm testing our infrastructure using the powershell command:
[System.TimeZoneInfo]::Local.Id
Which returns a string like
Eastern Standard Time
Our servers are all english right now, but I'm pretty sure this test would fail if I ran it on a non-english windows.
Is there a way to check the timezone without having to check it against an English string?
Rather than using [System.TimeZoneInfo]::Local.Id use [System.Timezoneinfo]::Local.BaseUtcOffset which will give you the result in terms of the number of hours difference between UTC time and the timezone of the server you are working with.
EDIT
#LotPings is correct that the BaseUtcOffset will not take into account DST, which may not matter if you are only concerned with verifying the timezones have not changed from your standard but if it is important you can instead use [System.TimeZoneInfo]::Local.GetUtcOffset($(get-date)) which will get you the current UTC offset.

Python find what is the epoch time after xxxx milliseconds

I am writing a python script which mainly involves decoration of console output.
I have some value called expiration_time which is in milliseconds. When I display expiration_time on console it is hard to find how much time exactly left to expire. User needs to do some calculation to know how much time is left.
So I decided to print epoch time instead. I want to do something like this:
epoch_time_at_which_expiration_will_happen = current_epoch_time + expiration_time_in_milliseconds
I want to output epoch_time_at_which_expiration_will_happen. How can I do it?
Not really sure what you are trying to output, the time at which expiration happens or the time until the expiration?
Either way, I would use a datetime object instead of the epoch time and convert the milliseconds to microseconds. The datetime objects allow you to do the math you want and to display the output formatted nicely.
https://docs.python.org/2/library/datetime.html

Parse DateTime when given as a Number/Double

I am working with some date times from a piece of weather hardware which logs to a .dbf file. I can pull this up from the ruby script/web server I am using, but I get numbers such as
41836.532638889
I am unsure how the date time is represented so having a hard time of knowing how to parse it. I would preferably like to parse it in Ruby, so code would be a plus, but I could figure out how to do it if I knew how it was represented.
The date is an OLE Automation formatted date which is common in Excel. As Google says it is
An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24.
The corresponding Ruby code is
def self.convert_time(t)
Time.at((t - 25569) * 86400).utc
end
The subtraction shifts the time to the day unix time starts (1 January 1970). Unix time is in seconds so converting days to seconds: 24*60*60=86400. Converting to utc time for convenience.
Try Time.at(your_number/double). You can then format it as required.
Time.at(41836.532638889)
=> 1970-01-01 12:37:16 +0100
41836 - number of days passed from 12/31/1899 (zero-date), 532638889 - number of seconds passed from the midnight of the date mentioned.

Resources