Recent

Author Topic: Want to see something funny?  (Read 1854 times)

tetrastes

  • Sr. Member
  • ****
  • Posts: 473
Re: Want to see something funny?
« Reply #15 on: January 24, 2023, 11:15:09 pm »

So I guess there is an issues parsing dates that have - as separator.

It may also be because I get a 4 digit year, and you only get a 2 digit year

No, at least at linux with fpc 3.2.2:
Code: Bash  [Select][+][-]
  1.  4.4951124173946759E+004
  2. This is Now:    25-1-23
  3. This is Nothing
  4. Now This is Now: 4.4951000000000000E+004

But this is strange date format. For my locale it should be 25.01.2023.

EDIT: I have to add uses clocale at unixes to get localized format.
« Last Edit: January 24, 2023, 11:27:30 pm by tetrastes »

tetrastes

  • Sr. Member
  • ****
  • Posts: 473
Re: Want to see something funny?
« Reply #16 on: January 25, 2023, 09:51:40 am »
How does the darn system give me the Wrong Format??

I can confirm this (windows 10, fpc 3.2.2):
Code: Bash  [Select][+][-]
  1.  4.4951563328148150E+004                                                                                              
  2. This is Now:    2023-янв-25                                                                                            
  3. This is Nothing                                                                                                        
  4. An unhandled exception occurred at $0000000100011C9F:                                                                  
  5. EConvertError: "2023-янв-25" is not a valid date format                                                                  
  6. $0000000100011C9F                                                                                                      
  7. $000000010000186F                                                                                                      
  8. $00000001000018D6                                                                                                      
  9. $000000010000D140                                                                                                      
  10. $00000001000016F0                                                                                                      
  11. $00007FF94BB47614                                            
  12. $00007FF94C3626A1
  13. Now This is Now:

It seems that StrToDate doesn't understand short date formats with months as strings, not numbers.

This works:
Code: Bash  [Select][+][-]
  1.  4.4951574145185186E+004
  2. This is Now:    2023-01-25
  3. This is Nothing
  4. Now This is Now: 4.4951000000000000E+004

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Want to see something funny?
« Reply #17 on: January 25, 2023, 10:15:07 am »
It seems that StrToDate doesn't understand short date formats with months as strings, not numbers.

https://gitlab.com/freepascal.org/fpc/source/-/issues/39757

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #18 on: January 26, 2023, 08:51:42 am »
OC DelGuy, please stop shouting at us by using these huge letters and the red color.

Wp, I thought AllCaps meant shouting.  I was just trying to soften the complaint.  In my own head, I was trying to sound like Kevin Hart in his Satellite Radio commercials.  Like when they come up to him and say "You don't have to listen to satellite radio in your car."  And they give him a phone and he says "What?"  Then they tell him he can hear it on his tablet.  So he throws the phone away and says: "What?"  Then a laptop and he tosses the tablet and says: "What?"  Amazon Alexa and he tosses the laptop and says: "What?"  In my mind, I sounded like him!  :D :D

The "No!" was actually like a sing-song sarcastic no.  I considered typing "Noooooooooooooo!!!", but that's like when you've fallen off a cliff.  You yell out "Noooooooooooo!!" as you're falling.

The "Sys don't think so.", was a play on Damon Wayans' (is the name spelled right?) "Homie, the clown".  His catch phrase was "Homie don't play that!"

So, don't sweat it, Wp.  I was just being sarcastic!  Trying to be funny.  Just keeping my head from overheating and throwing my computer out the window.  Wouldn't even go far...  My window is inch-thick plexi-glass.  It'd just bounce back and bonk me in the head! :o  :D :D

Why don't you simply write what you were expecting and what you got?

Because I thought you'd see the same thing I did.

I ask the computer for the time (now), tell it to convert it into a string (DateToString), then tell it to convert it back into a datecode (StrToDate), which I know is a float (hence the 4.4!@#$%^&*E+004), and display it on the console (WriteLn).

And what I saw (the output) was basically like talking to my wife!  I ask her what she wants from the supermarket (now).  She writes it down on a piece of paper (DateToStr).  I then tell her to look at the paper and ask: "What's that say?".  And she turns around and tells me: "I can't read that.  It's not formatted right! (this is the (StrToDate)) part.  And then I'm like: "You wrote the darned note!!!  And you're telling me it's in the wrong format???  You wrote it!!"    >:(  Oh Wifey, Wifey.  If you could only hear what you say!  :D ;D


That's the "funny" part that's actually Bull$#!t.  ::)  ::)

My guess is that you wonder why the line "WriteLn(StrToDate(DateToStr(Now))" does not print a date but a number.

No sir, Wp.  I wonder why I got the error that the format was wrong.  That line was where I got the runtime error.  That line didn't print on the console.  You might have confused the output that Martin_fr showed.  It seems to have worked on his computer, but not mine.

First of all: dates and floating point numbers are the same in Pascal. The date is the number of days past Dec 30 1899. The conversion function DateToStr(some_date) converts this number to a string formatted like a date (depending on details in your FormatSettings record). And StrToDate does the opposite: it takes a date-formatted string and converts it back to the count of days since Dec 30 1899.

The instruction "WriteLn(StrToDate(DateToStr(Now))" consists of four parts which are executed from the inside to the outside:
/1/ Now: determines the current date (and time) - always rember: as number of days sincd Dec 30 1899. This, for today, the value 44951. (The fractional part, BTW, represents the time between 0:00 and 24:00 - I am ignoring it here).
/2/ DateToStr(...): converts that day count to a nicely formatted date string, in your case probably '01/24/2023'
/3/ StrToDate(...): takes that date string and converts it back to date - but remember: date is just a number! So, the result is 44951
/4/ WriteLn(...): Prints this number. OK, since it is a floating point value the standard WriteLn() prints it in exponential notation. Nothing mystic here!

Yes, I know I ask a lot of questions here, But this I know.

The output of this sequence is absolutely correct.

Nope.  It's not correct.  It's also not incorrect.  It's nothing, since it didn't even execute the line.

Your post is very confusing and it is not clear what the problem is.

And Here I will concede.  You are correct.  I included one thing that was irrelevant (the assembler dialog) when I should have taken the screenshot with the actual error message.  My mistake.  Had I included the error message, I believe it might not have been confusing.
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #19 on: January 26, 2023, 08:57:11 am »
I havent tried yet but the first thing I would do is to remove unit "crt" from "uses".
Since you use Windows, I suggest you also put this line somewhere at top of your code like
Code: Pascal  [Select][+][-]
  1. program Consoleprog;
  2. {$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}

I investigate later what you do there  :D

Cool.  I'm answering this post on my Chromebook, so when i get back to my MSI Laptop  I'll type that in.  Probably like around 0900 California time.
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #20 on: January 26, 2023, 09:19:44 am »
Yes, The first pic is what I mean.
How can it work for you?

Different date separator. Your PC uses -  and mine use /

So I guess there is an issues parsing dates that have - as separator.
But I have not tested that.

Neither have I investigated, if that should work or not. (Though it seems that if it uses it for printing, one might expect it should).

Anyway for now: Good night.


---EDIT

It may also be because I get a 4 digit year, and you only get a 2 digit year

I don't get it Martin.  It's not like I'm asking two different computers.  It's the same machine!  It's like the two functions are looking (or not looking) at different places for the format.  It's like DateToStr is asking the system: "What's the format?" and converts it to that format, but the StrToDate function says:  "I don't care about the system format, I got my own format that I read and that's not it!  Kind of like a stubborn child.  Or maybe the DateToStr is being stubborn:  "I'm not asking the system what the format is.  I'm converting it my way".  I don't know.  I kind of got ticked off at the absurdity of this problem that I disappeared for a little while.  I'm over it now, so I'll start using all of y'allses suggestions and, hopefully, get to the bottom of this fiasco!
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #21 on: January 26, 2023, 09:22:00 am »
Test this please.
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}
  3.  
  4. uses
  5.   SysUtils;
  6.  
  7. var
  8.   dat: TDate;
  9.   LYear, LMonth, LDay: Word;
  10. begin
  11.   dat := Now; // this is current date and time
  12.   DecodeDate(dat, LYear, LMonth, LDay); // split it up
  13.   dat := EncodeDate(LYear, LMonth, LDay); // put it together again
  14.   writeln(dat); // now really just the date value is printed
  15.   writeln(DateToStr(dat)); // show it however your system is configured to show it
  16.   writeln(StrToDate(DateToStr(dat))); // compare that to the writeln(dat);, it must be same now
  17.   ReadLn; // let console open until you press return
  18. end.

I will test this at about 0900 Thursday, California time.
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #22 on: January 26, 2023, 09:36:32 am »
It seems that StrToDate doesn't understand short date formats with months as strings, not numbers.

I will stipulate that: "StrToDate doesn't understand short date formats with months as strings, not numbers."   But then my question is: "Why does DateToStr convert it to that format?  On the same machine?

I mean, do you understand what I'm saying?  Or am I so stupid that everyone is wondering what the heck I'm talking about?

 >:( >:(  Darn system!!  >:( >:(
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Want to see something funny?
« Reply #23 on: January 26, 2023, 09:49:13 am »
It seems that StrToDate doesn't understand short date formats with months as strings, not numbers.

I will stipulate that: "StrToDate doesn't understand short date formats with months as strings, not numbers."   But then my question is: "Why does DateToStr convert it to that format?  On the same machine?
My words in https://gitlab.com/freepascal.org/fpc/source/-/issues/39757... Reopen this bug report, and tell them that you do not understand their decision to not fix it... (I even had submitted a patch for it)

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #24 on: January 26, 2023, 09:52:35 am »
https://gitlab.com/freepascal.org/fpc/source/-/issues/39757

Code: Text  [Select][+][-]
  1.  
  2. Motivated by freepascal.org/lazarus/lazarus#39779 (closed) I thought about the issue that StrToDate and StrToDateTime allow only numeric values in their date/time parts. The format expected is taken from the ShortDateFormat of the FormatSettings record where the month is assumed to be in the one- or two-digit representation.
  3.  
  4. But why can there be only numbers in the month part? In the FormatSettings.ShortDateFormat the month can be specified as 'mmm' or even 'mmmm' - and this inserts the short or long month names in the strings created by DateToStr. However, these strings cannot be converted back to dates by calling the inverse StrToDate function? I know that Delphi does the same, it accepts only numeric month strings. But I don't see a real reason for this asymmetry.
  5.  

This is exactly what's happening to me!   He says that DateToStr outputs lettered months.  But that StrToDate won't convert it back!  This sounds like a Pascal issue and not a System issue.  They offer a patch that's supposed to solve the problem, but at the bottom of the page they say:
Code: Text  [Select][+][-]
  1.  
  2. Resolution:  Wont fix.
  3.  
  4.  
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #25 on: January 26, 2023, 09:55:47 am »
It seems that StrToDate doesn't understand short date formats with months as strings, not numbers.

I will stipulate that: "StrToDate doesn't understand short date formats with months as strings, not numbers."   But then my question is: "Why does DateToStr convert it to that format?  On the same machine?
My words in https://gitlab.com/freepascal.org/fpc/source/-/issues/39757... Reopen this bug report, and tell them that you do not understand their decision to not fix it... (I even had submitted a patch for it)

Wait, They decided not to fix it.  Or...   The solution (patch) didn't fix it?
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #26 on: January 26, 2023, 10:02:38 am »
Wp, Is this you?

Code: Text  [Select][+][-]
  1. I am enclosing a patch which extends the StrToDate function such that also the month text representations
  2. are accepted (both short and long forms). It requires only a few changes, and don't think that it will
  3. cause a noticeable speed drop. Since StrToDateTime internally calls StrToDate, it will be extended
  4. automatically.
  5.  
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Want to see something funny?
« Reply #27 on: January 26, 2023, 10:03:40 am »
They decided not to fix it, because there is another function, ScanDateTime, which does not have the issue.

Wp, Is this you?
Yes.

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #28 on: January 26, 2023, 10:16:46 pm »
They decided not to fix it, because there is another function, ScanDateTime, which does not have the issue.

Well, Golly Gee Willikers!  Why the heck am I not using ScanDateTime??!!

PS: Not shouting, just emphasizing...
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #29 on: January 26, 2023, 10:33:29 pm »
Test this please.

I did.  I got a runtime error on the same line.  See my screenshot.  It should be clearer as I shot the actual error message too, this time.

I'm going to try the ScanDateTime function...
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

 

TinyPortal © 2005-2018