I am using 'roo' gem, to read and parse the xlsx file. The file contains a start_time, which may have the user input values in the format of 06:00 AM. When the file is uploaded, I am getting the parameters converted to Sat, 30 Dec 1899 or "1899-12-30". I am wondering whether in any way, we can get the actual time format, the user mentioned in the file or can we convert the available parameter, to the actual file cell value.
Or is there any format or validations for xlsx file cell.
Thanks in advance.
This got resolved, as I changed the excel cell format to Text.
I've found that the xlsx reading libraries in Ruby, including Roo, get dates wrong. This is unfortunate but understandable, since excel uses both 'type' xml attributes and formatting rules that are awkward at best, and user-generated at worst.
Still, with effort, it is possible to get right most if not all of the time, which is why I wrote simple_xml_reader. If possible, use it, otherwise your solution will be the most reliable, since by my experience trying to use the previously-existing Ruby gems, they will only get it right a fraction of the time, if at all.
Changing excel cell format to text is the option only if you want to convert/parse the excel file once. What if you want the permanent solution? here you go -
xlsx.excelx_value(row,col)
This will give you the time value as representation of day i.e.
0.25 = 06:00 AM
0.50 = 12:00 PM
0.75 = 18:00 PM
and so on
you just need to convert this to minutes i.e. 0.25 * 1440 = 360 minutes = 06:00
You can even convert that into seconds 0.25 * 1440 * 60 * 60 = 21600 seconds
and then
Time.at(seconds).strftime("%H:%M:%S")
Related
In business central there is this data type named DateFormula, in it you can define things like '1D + 2H + 3S' (1 day, 2 hours and 3 seconds). I found out that i can convert this time range to a Date using CalcDate() however, Date objects dont contain the time information, which I do need.
There is no CalcDateTime() function in BC, nor does it mention converting DateFormula's to DateTime anywhere online it seems.
How can I convert a DateFormula to a DateTime object in BC?
OK so apparently it turns out that DateFormula datatype does not even support things like hours and seconds, only dates and no times.
Solved!
I am new to freemarker.
In freemarker, I would like to perform arithmetic expression on DateTime as follows:
${triggerTimestamp}-1h
But this is not working. Could anyone please help here?
FreeMarker doesn't do date/time arithmetic out of the box (as of 2.3.30 at least). It's expected that the data-model (context) contains the values that you actually want to display. One can implement some helper method in Java though.
You'll want to explore converting the date into unix/epoch time. If you add ?long to the end of the variable you'll convert the datetime into epoch time (which is in seconds) then do math and convert it back to a date. Your example would be
${(triggerTimestamp?long - 1 * 1000 * 60 * 60)?number_to_datetime?string.iso}
i have data in a csv file that looks like this. A timestamp and data, approximately 200 000 rows per file.
2015-10-19T22:15:30.12202 +02:00,62.7
2015-10-19T22:15:30.12696 +02:00,58.5
etc
I want to import it into matlab and convert the timestamp to a numeric format. The data is stored in a matrix of size N x 2. It should look like this:
736154.4935, 62.7
736154.4955, 58.5
etc
Looking only at the date conversion, below is the code i use. rawdata{2} is the vector of time strings ("2015-10-19T22:15:30.12696 +02:00"). I have to do an extra calculation since datenum only supports milliseconds, and not further.
for i = 1:length(rawdata{2})
currDate = strsplit(rawdata{2}{i}, ' ');
currDate = currDate{1};
add_days = str2double(currDate(24:25))/(100000*3600*24);
timestamp = datenum(currDate, 'yyyy-mm-ddTHH:MM:SS.FFF')+add_days;
data(i,1) = timestamp;
end
I have 1000+ files that each have 200 000+ rows like this. My code works, but it's too slow to be practical. Is there any way i can speed this up?
EDIT: After using profiling as suggested in the comments I found that strsplit took the most time. Since strsplit isn't really necessary in this case I was able to cut significant time off!
Now datenum is what takes up the majority of the time, but I'm not sure i can get around it. Any suggestions welcome!
I am making a program that will enable me to work out the avergae speed of something over a set distance
For this to work the user needs to input the start time and the end time.. I am not sure how you input time in a 24 hour format.
Furthermore I need to find the difference in the 2 times and then work out the speed.. which is distance/time taken.
Let's say distance was 1000 meters
I lack a bbc basic compiler but you should create some like this
print str$(secondsinday("22:50:01")-secondsinday("17:09:17"))
sub secondsinday(t$)
return val(left$(t$,2))*3600+val(mid$(t$,4,2))*60+val(right$(t$,2))
end sub
I saw some bbc basic examples and the formula should be the same, only the function syntax is diffrent (I'll try and convert it after some research)
In Ruby, how do I convert theFixnum 1291132740128 (milliseconds since the epoch) to the equivalent HTML5 global time & date string (Also see HTML5 time element explanation. E.g., 1979-10-14T12:00:00.001-04:00)?
My first attempt is:
> Time.at(1291132740128/1000.0).strftime("%Y-%m-%dT%H:%M:%S-%Z")
=> "2010-11-30T10:59:00-EST"
But, (1) how do I get the milliseconds? Does Time store the milliseconds?
And, (2) how do I get the timezone to be -0400 or -0500, depending on whether it's daylight savings time?
EDIT: Now that I think about it, perhaps it's better to keep it as 1291132740128 and do the conversion with JavaScript according to the browser location. What do you think?
1) %3N in strftime will give you milliseconds:
Time.at(1291132740128/1000.0).strftime("%Y-%m-%dT%H:%M:%S.%3N-%Z")
=> "2010-11-30T16:59:00.128-CET"
2) Isn't that automatic?
EDIT: What would happen if the user had his JS turned off in that case? I think it depends on the usage.
It doesn't show the miliseconds but you could try this:
Time.at(1291132740128/1000.0).xmlschema
=> "2010-11-30T16:59:00+01:00"