Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6149585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:28:39+00:00 2026-05-23T19:28:39+00:00

I have a code, that compare the last timestamp with the actual timestamp. If

  • 0

I have a code, that compare the last timestamp with the actual timestamp. If the actual timestamp is before the last timestamp, the systemtime has been manipulated. Because of the transition from or to daylight saving time, I work with UTC.
Now I would like to write an unit test for this special situation.

public void TransitionFromDSTToNonDST()
{
    var dayLightChangeEnd= TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.Now.Year).End;
    var stillInDaylightSavingTime= dayLightChangeEnd.Subtract(TimeSpan.FromMinutes(62));
    //stillInDaylightSavingTime.IsDaylightSavingTime() returns true
    //stillInDaylightSavingTime is 01.58 am
    var noDaylightSavingTimeAnymore= dayLightChangeEnd.Subtract(TimeSpan.FromMinutes(32));
    //noDaylightSavingTimeAnymore.IsDaylightSavingTime() returns false
    //noDaylightSavingTimeAnymore is 02.28 am
}

But actually I would like to simulate the following:

var stillInDaylightSavingTime = //for example 02.18 am BEFORE switching to Non-DST
var noDaylightSavingTimeAnymore = //for example 02.10 am AFTER switching to Non-DST

So the question is how can I define that a 02.18 am is either DST or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:28:39+00:00Added an answer on May 23, 2026 at 7:28 pm

    MSDN says:

    Conversion operations between time zones (such as between UTC and local time, or between one time zone and another) take daylight saving time into account, but arithmetic and comparison operations do not.

    IMO you should add your minutes in UTC and then convert to local kind.

    Here’s the (updated) code:

    var dayLightChangeEnd = TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.Now.Year).End.ToUniversalTime();
    var stillInDaylightSavingTime = dayLightChangeEnd.Subtract(TimeSpan.FromMinutes(62)).ToLocalTime();
    Console.WriteLine(stillInDaylightSavingTime);
    Console.WriteLine(stillInDaylightSavingTime.IsDaylightSavingTime());
    var noDaylightSavingTimeAnymore = dayLightChangeEnd.Subtract(TimeSpan.FromMinutes(2)).ToLocalTime();
    Console.WriteLine(noDaylightSavingTimeAnymore);
    Console.WriteLine(noDaylightSavingTimeAnymore.IsDaylightSavingTime());
    

    @WaltiD: I can’t comment but the code above prints 02:58 before and after DST shift.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that calls an ENTRY in a SUBROUTINE before the SUBROUTINE .
I have code that references a web service, and I'd like the address of
I have code that looks like the following, which works fine for displaying the
I have code that looks like: //System.Data.IDataRecord dr try { Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
I have code that looks like this: template<class T> class list { public: class
I have code that I want to look like this: List<Type> Os; ... foreach
I have code that uses Win API function RegSaveKeyEx to save registry entries to
I have code that uses jquery.slideup and jquery.slidedown How can i know that div
I have code that I want to compile on all unix systems, but if
I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.