Code Challenge 2021
Do you like Problems? Great! Here is one for you to solve. Please send in your response along with your resume and transcripts if you are interested in applying:
Imagine that one of your colleagues has approached you with the following code and asked you to review it. The method implemented here is central to a monthly reporting system. The purpose of the method is to determine month start and end times converted to UTC (Coordinated Universal Time).
- Any bug(s) you find
- Any thoughts or comments you might have with respect to the implementation
Please submit your response along with your cover letter and resume to the Student or Internship job posting on the Arcurve website.
/// Given a local date, get UTC date/time values for the first second of the first day
/// of the month containing that date and the first second of the first day of next month.
/// When run in Calgary, an input date of February 14, 2010 yields:
/// The first second of the first day of the month is: 7:00:00am, February 1, 2010 (UTC)
/// The first second of the first day of the next month: 7:00:00am, March 1, 2010 (UTC)
/// <param name="aDate">An arbitrary date, in localtime
/// <param name="utcMonthStart">Output: First day of the month in which aDate occurs, in UTC
/// <param name="utcNextMonthStart">Output: First day of the month after aDate, in UTC
void GetMonthRangeInUtc(DateTime aDate, out DateTime utcMonthStart, out DateTime utcNextMonthStart)
// compute the first day of the month containing aDate and successive months
DateTime monthStart = new DateTime;
for (int i = 0; i <= monthStart.Length; i++)
monthStart[i] = new DateTime(aDate.Year, aDate.Month++, 1);
// Compute the offset from UTC to our local time (UTC + offset =
TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(aDate);
// convert local times to UTC (UTC = localtime - offset)
utcMonthStart = monthStart.Subtract(utcOffset);
utcNextMonthStart = monthStart.Subtract(utcOffset);