Gem... As time goes by..
-
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";switch (strTime) { case "01": strReturn = "AM"; break; case "02": strReturn = "AM"; break; case "03": strReturn = "AM"; break; case "04": strReturn = "AM"; break; case "05": strReturn = "AM"; break; case "06": strReturn = "AM"; break; case "07": strReturn = "AM"; break; case "08": strReturn = "AM"; break; case "09": strReturn = "AM"; break; case "10": strReturn = "AM"; break; case "11": strReturn = "AM"; break; case "12": strReturn = "PM"; break; case "13": strReturn = "PM"; break; case "14": strReturn = "PM"; break; case "15": strReturn = "PM"; break; case "16": strReturn = "PM"; break; case "17": strReturn = "PM"; break; case "18": strReturn = "PM"; break; case "19": strReturn = "PM
That is quite spectacularly bad. - Unused parameter - Misnamed function (it is getting the hour part suffix, not Time) - Using strings to manage date/time info, and relying on the exact string (i.e. 2 != 02) - Incorrect coding or non-standard representation (01-24 instead of 00-23) - Duplicating framework functionality (myDateTime.ToString("hh tt")) - Repeat code in case blocks instead of a single test for all included conditions Anyone spot any more?
-
That is quite spectacularly bad. - Unused parameter - Misnamed function (it is getting the hour part suffix, not Time) - Using strings to manage date/time info, and relying on the exact string (i.e. 2 != 02) - Incorrect coding or non-standard representation (01-24 instead of 00-23) - Duplicating framework functionality (myDateTime.ToString("hh tt")) - Repeat code in case blocks instead of a single test for all included conditions Anyone spot any more?
I laughed out loud when I saw this one... Possibly the funniest function I've seen in the hall of shame.
-
It's also wrong : "24" is "AM" :) Cheers
If you can read this, you don't have Papyrus installed
You never get "24" it's "00"
my Tip/Tricks[^] | "Rajesh-Puli" now "Rajesh-Anuhya"
-
You never get "24" it's "00"
my Tip/Tricks[^] | "Rajesh-Puli" now "Rajesh-Anuhya"
That depends entirely on the input, we're not dealing with a real time format here. As said by others here, thse method is wrong in many respects. My comment denoted that there are 11 "AM" entries and 13 "PM" entries. So if "24" is input, the output should logically be "AM", not "PM". Cheers
If you can read this, you don't have Papyrus installed
-
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";switch (strTime) { case "01": strReturn = "AM"; break; case "02": strReturn = "AM"; break; case "03": strReturn = "AM"; break; case "04": strReturn = "AM"; break; case "05": strReturn = "AM"; break; case "06": strReturn = "AM"; break; case "07": strReturn = "AM"; break; case "08": strReturn = "AM"; break; case "09": strReturn = "AM"; break; case "10": strReturn = "AM"; break; case "11": strReturn = "AM"; break; case "12": strReturn = "PM"; break; case "13": strReturn = "PM"; break; case "14": strReturn = "PM"; break; case "15": strReturn = "PM"; break; case "16": strReturn = "PM"; break; case "17": strReturn = "PM"; break; case "18": strReturn = "PM"; break; case "19": strReturn = "PM
-
It's also wrong : "24" is "AM" :) Cheers
If you can read this, you don't have Papyrus installed
ISO 8601 allows 24:00 as the end of the day, so it would be PM; AM starts at 00:00 (not that ISO 8601 recognizes AM/PM of course).
-
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";switch (strTime) { case "01": strReturn = "AM"; break; case "02": strReturn = "AM"; break; case "03": strReturn = "AM"; break; case "04": strReturn = "AM"; break; case "05": strReturn = "AM"; break; case "06": strReturn = "AM"; break; case "07": strReturn = "AM"; break; case "08": strReturn = "AM"; break; case "09": strReturn = "AM"; break; case "10": strReturn = "AM"; break; case "11": strReturn = "AM"; break; case "12": strReturn = "PM"; break; case "13": strReturn = "PM"; break; case "14": strReturn = "PM"; break; case "15": strReturn = "PM"; break; case "16": strReturn = "PM"; break; case "17": strReturn = "PM"; break; case "18": strReturn = "PM"; break; case "19": strReturn = "PM
maybe the programmer was paid by the line
-
That is quite spectacularly bad. - Unused parameter - Misnamed function (it is getting the hour part suffix, not Time) - Using strings to manage date/time info, and relying on the exact string (i.e. 2 != 02) - Incorrect coding or non-standard representation (01-24 instead of 00-23) - Duplicating framework functionality (myDateTime.ToString("hh tt")) - Repeat code in case blocks instead of a single test for all included conditions Anyone spot any more?
Some more: - no test to verify input value range or format (this would be neglectable if using correct types as you've already implied with your point 'Using strings') - using switch without default case - using hard coded strings for "AM" and "PM" - combining a yes/no test with an unrelated display functionality into one function (note that a test for AM and PM implies that a 24h format is being converted to a 12h format, and thus the test needs to be repeated in order to convert the number part!)
-
ISO 8601 allows 24:00 as the end of the day, so it would be PM; AM starts at 00:00 (not that ISO 8601 recognizes AM/PM of course).
Do 24:00 and 00:00 occur at the same time then, just different notations?
-
Do 24:00 and 00:00 occur at the same time then, just different notations?
Yes, different notations for the same timepoint.
-
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";switch (strTime) { case "01": strReturn = "AM"; break; case "02": strReturn = "AM"; break; case "03": strReturn = "AM"; break; case "04": strReturn = "AM"; break; case "05": strReturn = "AM"; break; case "06": strReturn = "AM"; break; case "07": strReturn = "AM"; break; case "08": strReturn = "AM"; break; case "09": strReturn = "AM"; break; case "10": strReturn = "AM"; break; case "11": strReturn = "AM"; break; case "12": strReturn = "PM"; break; case "13": strReturn = "PM"; break; case "14": strReturn = "PM"; break; case "15": strReturn = "PM"; break; case "16": strReturn = "PM"; break; case "17": strReturn = "PM"; break; case "18": strReturn = "PM"; break; case "19": strReturn = "PM
Dude :doh: You got to be making that up!
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
-
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";switch (strTime) { case "01": strReturn = "AM"; break; case "02": strReturn = "AM"; break; case "03": strReturn = "AM"; break; case "04": strReturn = "AM"; break; case "05": strReturn = "AM"; break; case "06": strReturn = "AM"; break; case "07": strReturn = "AM"; break; case "08": strReturn = "AM"; break; case "09": strReturn = "AM"; break; case "10": strReturn = "AM"; break; case "11": strReturn = "AM"; break; case "12": strReturn = "PM"; break; case "13": strReturn = "PM"; break; case "14": strReturn = "PM"; break; case "15": strReturn = "PM"; break; case "16": strReturn = "PM"; break; case "17": strReturn = "PM"; break; case "18": strReturn = "PM"; break; case "19": strReturn = "PM
The AM/PM suffix only makes sense on a 12-hour system, not a 24-hour clock. If you use an 24-hours based day, you already know whether the time is in the morning or evening. Otherwise, the 8 O'Clock needs the AM/PM suffix to discriminate between 8:00 (8 AM) and 20:00 (8 PM). It's a ridiculous format, and that mistake is as grave as the function is coded. It'd be best to use the date-format as specified in the users' settings, or to use a predefined format. Making up your own format requires owning a country.
Bastard Programmer from Hell :suss:
-
The AM/PM suffix only makes sense on a 12-hour system, not a 24-hour clock. If you use an 24-hours based day, you already know whether the time is in the morning or evening. Otherwise, the 8 O'Clock needs the AM/PM suffix to discriminate between 8:00 (8 AM) and 20:00 (8 PM). It's a ridiculous format, and that mistake is as grave as the function is coded. It'd be best to use the date-format as specified in the users' settings, or to use a predefined format. Making up your own format requires owning a country.
Bastard Programmer from Hell :suss:
Eddy Vluggen wrote:
The AM/PM suffix only makes sense on a 12-hour system
true :thumbsup:
-
That is quite spectacularly bad. - Unused parameter - Misnamed function (it is getting the hour part suffix, not Time) - Using strings to manage date/time info, and relying on the exact string (i.e. 2 != 02) - Incorrect coding or non-standard representation (01-24 instead of 00-23) - Duplicating framework functionality (myDateTime.ToString("hh tt")) - Repeat code in case blocks instead of a single test for all included conditions Anyone spot any more?
-
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";switch (strTime) { case "01": strReturn = "AM"; break; case "02": strReturn = "AM"; break; case "03": strReturn = "AM"; break; case "04": strReturn = "AM"; break; case "05": strReturn = "AM"; break; case "06": strReturn = "AM"; break; case "07": strReturn = "AM"; break; case "08": strReturn = "AM"; break; case "09": strReturn = "AM"; break; case "10": strReturn = "AM"; break; case "11": strReturn = "AM"; break; case "12": strReturn = "PM"; break; case "13": strReturn = "PM"; break; case "14": strReturn = "PM"; break; case "15": strReturn = "PM"; break; case "16": strReturn = "PM"; break; case "17": strReturn = "PM"; break; case "18": strReturn = "PM"; break; case "19": strReturn = "PM
Or... Assuming the string has only military time with no date:
string strReturn = DateTime.Parse(DateTime.MinValue.ToString("MM/dd/yyyy ") + strTime).ToString("tt");
If it has date and time:
string strReturn = DateTime.Parse(strTime).ToString("tt");
Kevin Rucker, Application Programmer QSS Group, Inc. United States Coast Guard OSC Kevin.D.Rucker@uscg.mil "Programming is an art form that fights back." -- Chad Hower
-
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";switch (strTime) { case "01": strReturn = "AM"; break; case "02": strReturn = "AM"; break; case "03": strReturn = "AM"; break; case "04": strReturn = "AM"; break; case "05": strReturn = "AM"; break; case "06": strReturn = "AM"; break; case "07": strReturn = "AM"; break; case "08": strReturn = "AM"; break; case "09": strReturn = "AM"; break; case "10": strReturn = "AM"; break; case "11": strReturn = "AM"; break; case "12": strReturn = "PM"; break; case "13": strReturn = "PM"; break; case "14": strReturn = "PM"; break; case "15": strReturn = "PM"; break; case "16": strReturn = "PM"; break; case "17": strReturn = "PM"; break; case "18": strReturn = "PM"; break; case "19": strReturn = "PM
your solution is different from original. What if the parameter string is not a number or number any other than one in switch? The original will return empty string while yours - eather throw or return PM instead.
-
your solution is different from original. What if the parameter string is not a number or number any other than one in switch? The original will return empty string while yours - eather throw or return PM instead.
I know what you mean mate... the solution I put was just to show that whole function can be redundant. If I have to code it I will make sure of all exception and validations on client and server...
Zen and the art of software maintenance : rm -rf * Math is like love : a simple idea but it can get complicated.
-
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";switch (strTime) { case "01": strReturn = "AM"; break; case "02": strReturn = "AM"; break; case "03": strReturn = "AM"; break; case "04": strReturn = "AM"; break; case "05": strReturn = "AM"; break; case "06": strReturn = "AM"; break; case "07": strReturn = "AM"; break; case "08": strReturn = "AM"; break; case "09": strReturn = "AM"; break; case "10": strReturn = "AM"; break; case "11": strReturn = "AM"; break; case "12": strReturn = "PM"; break; case "13": strReturn = "PM"; break; case "14": strReturn = "PM"; break; case "15": strReturn = "PM"; break; case "16": strReturn = "PM"; break; case "17": strReturn = "PM"; break; case "18": strReturn = "PM"; break; case "19": strReturn = "PM
You should focus on making it future-proof.
I wanna be a eunuchs developer! Pass me a bread knife!
-
Yes, different notations for the same timepoint.
-
The Army (at least) took 2400 as the end of the day...and never acknowledged 0000 as existing. :p
So I rounded up my camel Just to ask him for a smoke He handed me a Lucky, I said "Hey, you missed the joke." My Mu[sic] My Films My Windows Programs, etc.