3
\$\begingroup\$

In my program, I display the compilation time which is calculated from the AssemblyVersion attribute. The attribute is set to automatically generate a version number (with asterisk).

As you know probably, the build is equal to the number of days since January 1, 2000 (local time), and revision is equal to the number of seconds since midnight (local time, without taking into account time zone adjustments for daylight saving time), divided by 2! See the documentation of attribute for more information.

My code parses the version number to calculate the compilation time according to the previous statement with taking account time zone adjustments for daylight saving time! But, I'm not sure about the last part.

DateTime date = DateTime(2000, 1, 1, 0, 0, 0);  // January 1, 2000 at midnight

date = date.AddDays(build);

// Time zone adjustments for daylight saving time
if (TimeZoneInfo::FindSystemTimeZoneById("Central Europe Standard Time")->IsDaylightSavingTime(date)) // I'm living in Switzerland, so CEST
{
    date = date.AddHours(1);
}

date = date.AddSeconds(revision * 2);

Is my code correct? Can I optimize this?

\$\endgroup\$
  • \$\begingroup\$ Do you need the time zone of the computer where the assembly was built or do you need your time zone? \$\endgroup\$ – kerem Jan 7 '15 at 17:57
  • \$\begingroup\$ @kerem I need my time zone, the time zone where the assembly was compiled. Or is it better to choose the time zone of the user? \$\endgroup\$ – Kevin Vuilleumier Jan 8 '15 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.