开发者

find ALL methods of getting current date/time in VB.net

开发者 https://www.devze.com 2023-01-13 17:26 出处:网络
I have a 500K+ lines vb.net app, written by 10+ different devs over the past 5 years. Many times it gets the system time and/or date and relies on it.

I have a 500K+ lines vb.net app, written by 10+ different devs over the past 5 years. Many times it gets the system time and/or date and relies on it.

Now I have to re-run real cases thru the program for regression testing purposes, and it screws up cases where the date/time matter. My fix is easy, just replace all the areas in the program that get cur开发者_如何学Crent date/time with a sub that gets the current date/time, UNLESS I'm testing, in which case it will return the date/time of the original run.

I have tried searching the sourcecode for the obvious 'current date/time' functions:

Now
DateAndTime.TimeOfDay
Date.ToDay

However, if I miss one, I LOSE.

Can anybody please list more ways to get the current time, that might be hidden in the source code, that I can search for? Note: It's pretty clear none of the 3rd party libs in this system are returning date, well, one is, but I've caught it. so just from .net or vb. Thanks.


Use the technique described by @Hans Passant. For a complete list of VB.NET functions related to system clock, look here.

DateString
Now
TimeOfDay
Timer
TimeString
Today
DateAdd
DateDiff
DatePart
DateSerial
DateValue
Day
IsDate
Month
MonthName
Weekday
Hour
Minute
Second
TimeSerial
TimeValue


Find one, right-click, Find All References.

Reflector can help too. Right-click the property getter, Analyze, Used by.


The following also get the current date and time:

DateTime.Now
DateTime.UtcNow
DateTime.Today
DateTimeOffset.Now
DateTimeOffset.UtcNow

Is that all of them? Somehow I doubt it.

0

精彩评论

暂无评论...
验证码 换一张
取 消