It's really hard to answer your question without a minimal, reproducible example, but I will make an attempt.
In your code, by using DateTimeOffset.Now
you are using the system's local time zone as a basis of comparison. Instead, you should get the time in a specific time zone before making your comparison:
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
DateTimeOffset now = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, tzi);
Then you can use now
in your comparison and it will reflect the current time in the Pacific time zone, both when DST is in effect and when it is not.
Note that I inferred a few things from your question, comments, and symptoms you described:
Your item.LunchTime
is a DateTime
type. If it's actually a DateTimeOffset
type, then the comparison would be made correctly regardless of time zone. In other words, DateTime
comparison is based on the date and time as presented while DateTimeOffset
comparison is based on the equivalent UTC timestamp.
Your server is a Windows server. I believe GoDaddy only uses Plex for it's Windows hosting (from what I could gather from searching their documentation).
Because you said everything worked until last fall, I assume you meant it worked until DST ended. In other words, while Pacific Time was UTC-7 the value you got from DateTimeOffset.Now
was what you expected, but when Pacific Time returned to UTC-8, you still got values with a UTC-7 offset as before.
If that last point is correct, then likely your server is set for Arizona rather than for Pacific Time. Since GoDaddy is an Arizona-based company, this is plausible.
It may or may not be possible to change the system's time zone depending on how much of the hosting environment GoDaddy has exposed. I can see from Plesk's docs that they do indeed give a Date and Time settings panel - but I'm not sure whether GoDaddy exposes it to you or not.
Again, my recommendation would be to ignore the system-local time zone and not try to change it. Instead, alter your code to use a specific time zone as shown. Put it in a helper function somewhere in your code if that makes it easier to use throughout your applicaiton.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…