Student Coding Challenge

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// <summary>
/// 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.
/// </summary>
/// <example>
/// 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)
/// </example>
/// <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[2];
    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 =
    localtime).
    TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(aDate);

    // convert local times to UTC (UTC = localtime - offset)
    utcMonthStart = monthStart[0].Subtract(utcOffset);
    utcNextMonthStart = monthStart[1].Subtract(utcOffset);
}