New answers tagged

0

Minor Changes Method name reduce suggests a generic API method that would take a predicate and accumulator. Instead, it's very specific in returning a custom array and mapping a string to Date. I would call it getCalendarByMinimumRecommendedTime instead. Prefer the use of const over let for immutable data: const providerCalendars and const ...


1

I see the point of the commenters: why implement this, if it has already been implemented? However, I still see benefit for such a question in an interview process. Given the right analysis, you can see how the developer thinks and what question he asks, which is IMHO more important than the actual code. Questions could be: What coding guidelines shall I ...


0

Last answer deleted (instead of substantially revising). Notes (see comments in code) CalendarSpan signed (date1 > date2 => negative span) Extension overload of DateTime.Add() taking CalendarSpan argument Unit test approach (see Main() which iterates positive and negative differences, using DateTime functions to check integrity of results) ` using ...


1

From Comments Have you tested performance of copying data of a single day to a temporary table, truncating the target table, and re-inserting the copied data back to the target table? Yes, it's not taking much time to copy or insert, it is taking time to delete and select. One of the column has huge XML string. Proposed Solution Since inserting and ...


1

Why are you getting day in function getWeekday and never using it? Use a IIF (Immediately Invoked Function) to close over constants so they do not need to be created each time you call the function that uses them (Note optimizer will cache such constants, though not on the first pass) Don't add unneeded details to names. booking is unrelated to the functions ...


2

Since the question gives a couple of guarantees about the input, take advantage of them. If you want to communicate these preconditions, assert them. Something like string timeConversion(string s) { // Assume input is in the format hh:mm:ssAM or hh:mm:ssPM assert(s.length() == 10); int size = s.length(); ... ... if(s[size-2]=='A'){ ...


1

I think what you have is fine. There are many ways this can be done. For example: string timeConversion(string s) { int hours = stoi(s.substr(0,2)); if (s[8] == 'A') { if (hours == 12) hours = 0; } else { if (hours == 12) hours = 12; else hours += 12; } return ((hours < 10) ? "0" :"") + to_string(...


1

Review You don't need to calculate the difference from two temporary values GetUTCDate and GETDATE. SELECT @DifferenceInHoursBetween = DATEDIFF(HH,GetUTCDate(), GETDATE()) Proposed Solution Instead, you could apply the local time zone offset to the specified datetime. SELECT USER_ID, CreateDate AS [DateTime IN UTC], CONVERT(datetime, ...


3

In addition: "Always specify a radix when using parseInt." -- MDN parseInt documentation When getValue() is given a malformed string, it ignores the malformed parts without letting anyone know something went wrong. For example, 2 h 500 m 600 s returns 0. It is better to throw an error when the input isn't valid (so the caller can more easily figure out why ...


1

function toSeconds(input_string){ var int_array = input_string.split(/h|m|s/); return parseInt(int_array[0]) * 3600 + parseInt(int_array[1]) * 60 + parseInt(int_array[2]); }


10

Named Capture Groups JavaScript RegExp has named capture groups that can make life a lot simpler when dealing with complicated RegExp. Combined with destructuring assignment you can extract the named hours minutes and seconds as follows. function toSeconds(time) { const {groups: {h = 0, m = 0, s = 0}} = /(?<h>\d*)h(?<m>\d*)m(?<s>\d*)/...


14

getValue(str) is such a vague name for the function and its parameter, it could mean anything! Furthermore, "get" implies that this is a getter function that retrieves something, which is not the case. Your regex is ineffective. Capturing parentheses could be useful, but you didn't actually use them right, such that you ended up having to pass a dirty ...


1

Adding to what Gerard has answered, there are some PHP libraries that deal with time very well which you could implement. One example is Carbon. I would separate out your date comparisons into its own function. May be useful elsewhere and is a little clearer. Everything in your for loop up to your first if statement could be its own function. You could ...


1

The algorithm does not allow for the possibility of a transition from daylight time to standard time or vice versa. Without knowing the mechanism for obtaining the date and time, it's impossible to say if the algorithm needs to be aware of time zones. In principle, the student could be attending by video conference and be in a different time zone. If the ...


5

You'll need to use by.x to get around setting x's key. Also, note that foverlaps can merge on any number of keys, and then do the overlaps only on the final two. What that means here is that you can do the x.Receiver == i.Receiver filter up-front, which also simplifies the clean-up step. x = as.data.table(x) x[ , end := DateTimePST] y = as.data.table(y) ...


Top 50 recent answers are included