|
That would be evil
Real programmers use butterflies
|
|
|
|
|
Yes?
Wrong is evil and must be defeated. - Jeff Ello
Never stop dreaming - Freddie Kruger
|
|
|
|
|
Found this gem in our codebase...
public static class DateTimeExtensions
{
public static DateTime EndOfMonth(this DateTime dt)
{
return dt.Date.AddMonths(1).AddDays(-1);
}
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Ah.
I can see a problem developing there. I assume he tested it on the first of the month, and it worked fine?
Here is my stab at it:
public static DateTime LastOfMonth(this DateTime dt)
{
int daysInMonth = DateTime.DaysInMonth(dt.Year, dt.Month);
return dt.FirstOfMonth().AddDays(daysInMonth - 1).AtMidnight();
} As seen before: DateTime Extensions to Make Some Simple Tasks a Little More Readable[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Actually, he had unit tests in place, but all the dates tested were on the first day of the month.
My fix was:
return new DateTime(dt.Year, dt.Month, 1).AddMonths(1).AddDays(-1);
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
modified 15-Jun-20 9:14am.
|
|
|
|
|
I guess it's true for tests as well: GIGO ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
And why not simply use DateTime.DaysInMonth ?
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Because the programmer wanted the attention of being presented here?
|
|
|
|
|
Makes sense
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
|
Rob Grainger wrote: return new DateTime(dt.Year, dt.Month, 1).AddMonths(1).AddDays(-1);
This is exactly my EndOfMonth extension function in dotNet.
|
|
|
|
|
This gets you the last *date* of the month, but if you’re actually looking for the “end” of the month and don’t want fencepost errors, you’d want the first of the next month (with no time component) and then use a strict less-than in your comparisons.
|
|
|
|
|
Not to be pernickity but I guess it is going to depend on the intention of the method. If a trial runs for a month then perhaps from a given date that would be the end of the month
However, the intention is not clear from the method name so one may very well assume that it represents the date for the last day in the month of the given date.
|
|
|
|
|
Personally, I feel that an extension method on DateTime should apply to all possible DateTime instances. Otherwise, it can be defined to match circumstances, as long as that is clear from the name.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
30 days have September, all the rest I can't remember.
|
|
|
|
|
I resemble that remark.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
|
That can't be real. Come on. How stupid an entire team has to be to let this run in production. Has to be a joke. And if this is intranet, why are you bothered with form based authentication? Just do AD look up or something.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
I want to believe this is a joke too and that an entire team cannot be that stupid...
But I'm not so sure
I once worked for a company who had their own "security framework".
The idea was that you entered a username and password, the application would use those to login to SQL Server and if that succeeded you were logged in.
So a user in SQL Server was a user in the system and a user in the system couldn't exist without a user in SQL Server.
It supported Windows authentication too.
The application had a form to enter new users and those users would be added in SQL Server too.
It was a WinForms application on intranet so I guess it wasn't much of an issue, but it's really not how to do authentication
I think we ran into some issues at one point though.
They built it when I was already an employee and I advised against it and advised a more "traditional" approach, but I was just a junior back then and according to the technical director this really was the best method.
Cost him months to build too
I just remembered the issue we ran into!
After a backup or some such, all users ended up being "orphaned" and everybody lost access to the database and the application.
Happened more than once too.
A 200+ employee company
|
|
|
|
|
Only thing then left was to hand over keys to data center to users.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
We were lucky our users were enormous digital illiterates
|
|
|
|
|
I had a client that was doing the same thing - fortunately they were updating their web app so I was able to rip all that out. However they also had code that would record every login event to a log file, recording the username and password in a publically accessible plain text file (within their LAN).
|
|
|
|
|
lw@zi wrote: How stupid an entire team has to be Just because it's a mid-sized organisation doesn't mean there's an "entire team". All too often the "IT Department" is one person (as a freelancer, I've been the "IT Department" to quite a few companies of that size and above). It may not even be an IT professional - this may be a tool knocked up for personal use, spotted by a manager, who said "roll that out to everyone and stick a username/password check on the front". If it's someone who spent 5 hours learning basic Javascript but no other IT background, it's no surprise stuff like this goes live. And it works so the manager would probably be delighted.
What I wonder more about is
if ("true" === "true") {
return false;
} Why???
|
|
|
|
|
The method is DoesUserWantToLogin, question is "Do you not want to login", response was true so return value was false. It is so straightforward. What is confusing you?
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
Not confused... just in wonderment!
|
|
|
|