How to prevent wrapping around of time when adding them in spreadsheet? - time

I have absolute values of time (as in stopwatch not date/time) in various cells and I would like to add them and keep them the same format (as an absolute value). I have formatted the cells using hh:mm:ss time format but when I add two values like:
22:34:00
4:00:00
I see: 2:34:00 because of wrapping around the 24-hour time format, instead of 26:34:00.
How can I do this with OO-Calc?

Well, the solution seemed to be to use the format, [HH]:MM:SS instead of HH:MM:SS.

Related

Regex: Grouping with OR

I'm new here, so please don't scold me for misspellings etc.
What I need to do is to rename a bunch of files with a date in different formats at the beginning of their names, like:
05.07.2020-abc.pdf
2020.07.05-pqr.pdf
Instead of writing a different expression for each formatting, eg.
^(\d{2})\.(\d{2}).(\d{4})(.+) => $3-$2-$1$4
Example
02.11.2022-abc.pdf => 2022-11-02-abc.pdf
I'd like to do it in one fell swoop using the OR operator "|" but I have no idea how to formulate the groupings etc. Can one have nested groupings in regex?
Any ideas? Thank in advance!
#The fourth bird:
No (.+) needed. You're right, I condensed my actual expression and could have taken it out.
The different date 'formats' I mean are dd.mm.yyyy and yyyy.mm.dd respectively, and I need to convert both to yyyy-mn-dd
So,if the format is dd.mm.yyyy I have to flip the string, so to say, else I just need to replace the dots by hyphens.
The OS is Android, and for this operation I use Solid Explorer multi search & replace using regex.
I hope I made myself clear this time around ;-)

Plain Text to Duration conversion google sheets

I'm trying to set up a form where colleagues can input times and durations and other elements will auto-fill.
I've got the input converting plain text to time using:
=text(time(left(X4,2),right(X4,2),),"HH:mm AM/PM")
But haven't worked out how to do the same for duration (ideally inputting in minutes e.g. 90 equates to 01:30:00).
Thanks
First of all, your formula doesn't convert to time because the output of text is plain text. To get actual time, use time(left(X4,2),right(X4,2),) and format cells with this formula as HH:mm AM/PM.
Similarly for duration: if X4 has "90", then time(0,X4,0) will display the duration of 1:30:00 provided the cell is formatted as duration.

Get the current date/time in Ruby as string without delimiters?

Is there any good way to get the current date/time in Ruby as a string without separators, not having to use Time.now.strftime('%Y%m%d'), etc.?
The output I'm looking for is something like "20151002112001" or similar, with all digits and no separators, human-readable form, not Unix time.
I found out that by using Active Support, this can be easily done:
require 'active_support/core_ext/time/conversions'
Time.now.to_formatted_s(:number) # => "20151002112419"
Since I already depend on Active Support, this turned out to be the quickest and easiest way to get this done by far.
You can use .to_i on a Time object to get a number representing Unix-time.
You can convert Date or DateTime objects to Time with .to_time. For example:
string = "#{Date.today.to_time.to_i}"
# "1443769200"
If you need to get certain attributes but don't like strftime, you can use methods of Date. For example, you might do something like
date = Date.today
string = "#{date.year}-#{date.month}-#{date.day}"
# "2015-10-2"
This all works without Active Support, but you still need to require 'date'.

Figure date format from string in ruby

I am working in a simple data loader for text files and would like to add a feature for correctly loading dates into the tables. The problem I have is that I do not know the date format before hand, and it will not be my script doing the inserts - it has to generate insert statements for later use.
The Date.parse is almost what I'd need. If there was a way to grab the format it identified on the string in a way I could use to generate a to_date(...)(Oracle standard) would be perfect.
An example:
My input file:
user_name;birth_date
Sue;20130427
Amy;31/4/1984
Should generate:
insert into my_table values ('Sue', to_date('20130427','yyyymmdd'));
insert into my_table values ('Amy', to_date('31/4/1984','dd/mm/yyyy'));
Note that it is important the original string remains unchanged - so I cannot parse it to a standard format used in the inserts (it is a requirement).
At the moment I am just testing a bunch of regexes and doing some validation, but I was wondering if there was a more robust way.
Suppose (using for example String#scan), you extracted an array of the date strings from a single file. It may be like:
strings = ["20130427", "20130102", ...]
Prepare in advance an array of all formats you can think of. It may be like:
Formats = ["%Y%m%d", "%y%m%d", "%y/%m/%d", "%m/%d/%y", "%d/%m/%y", ...]
Then check all formats that can parse all of the strings:
require "date"
formats =
Formats.select{|format| strings.all?{|s| Date.strptime(s, format) rescue nil}}
If this array formats includes exactly one element, then that means the strings were unambiguously parsed with that format. Using that format, you can go back to the strings and parse them with that format.
Otherwise, either you failed to provide the appropriate format within Formats, or the strings remained ambiguous.
I would use the Chronic gem. It will extract dates in most formats.
It has options to resolve the ambiguity in the xx/xx/xxxx format, but you'd have to specify which to prefer when either match.

Parameterizing a freemarker builtin

Can the builtin part of a expression in freemarker be parameterized?
If so, how?
For example, a date can be formatted with the following builtins:
${openingTime?string.short}
${openingTime?string.medium}
${openingTime?string.long}
${openingTime?string.full}
Can the string.short/string.medium/... builtin names be parameterized too?
For example, I'd like to do something like:
${openingTime?${mydatefmt}}
where mydatefmt is 'string.short' or any valid format.
That would make it easily possible to change the date formats on a freemarker page.
I want to limit the change to a page/file and not apply globally.
Does something like this need to be put into a Freemarker macro that might anticipate all possible types of date formats that might be needed?
One approach is using openingTime?string(pattern), where pattern can be any kind of expression that evaluates to a string. But it's quite verbose and somewhat slow, as the patter will be re-parsed again and again.
Another approach is setting the date_format, time_format and datetime_format FreeMarker settings, and then just write ${openingTime}. (Actually, if openingTime isn't a javax.sql subclass of java.util.Date, you have to write ${openingTime?datetime}, because the Java API doesn't know the difference date-time, time and date-only, but this is another story.) FreeMarker settings can be set globally (better said, on Configuration-level), on template-level (but you don't do that usually), or on the Environment. See http://freemarker.org/docs/pgui_config_settings.html. The last can be done in FTL too, like with <#setting datetime_format = 'yyyy-MM-dd HH:mm:ss zzzz'>.
You have to specify the formatting pattern explicitly : ${openingTime?string("yyyy-MM-dd HH:mm:ss zzzz")}
The date format can be a expression, for example : ${openingTime?string(mydatefmt)}.

Resources