Recent

Author Topic: Suggestion for "jForms" "GetDateTimeDecode"  (Read 2957 times)

ADiV

  • Jr. Member
  • **
  • Posts: 90
    • ADiV Software
Suggestion for "jForms" "GetDateTimeDecode"
« on: October 20, 2018, 10:57:34 am »
Hi guys, I created this "GetDateTimeDecode" function to be able to manipulate dates and times, if Mr. @jmpessoa likes it I could include it in the "jForm" class to complement the "GetDateTime" function already included in "androidwidget.pas".

Code: Pascal  [Select][+][-]
  1. //public
  2. function  GetDateTimeDecode(
  3.                              var day : integer; var month : integer; var year : integer;
  4.                              var hours : integer; var minutes: integer; var seconds : integer ) : boolean;
  5.  
  6. // ...
  7.  
  8. function jForm.GetDateTimeDecode(
  9.                              var day : integer; var month : integer; var year : integer;
  10.                              var hours : integer; var minutes: integer; var seconds : integer ) : boolean;
  11. var
  12.  strDateTime : string;
  13. begin
  14.  result := false;
  15.  
  16.  strDateTime := GetDateTime;
  17.  
  18.  day := 0; month := 0; year := 0;
  19.  hours := 0; minutes := 0; seconds := 0;
  20.  
  21.  try
  22.    year  := strToInt( copy(strDateTime, 1, 4) );
  23.    month := strToInt( copy(strDateTime, 6, 2) );
  24.    day   := strToInt( copy(strDateTime, 9, 2) );
  25.    hours   := strToInt( copy(strDateTime, 12, 2) );
  26.    minutes := strToInt( copy(strDateTime, 15, 2) );
  27.    seconds := strToInt( copy(strDateTime, 18, 2) );
  28.  except
  29.    exit;
  30.  end;
  31.  
  32.  result := true;
  33.  
  34. end;
« Last Edit: October 20, 2018, 01:01:26 pm by TR3E »

A.S.

  • Jr. Member
  • **
  • Posts: 76
Re: Suggestion for "jForms" "GetDateTimeDecode"
« Reply #1 on: October 20, 2018, 12:11:25 pm »
Which format is used for strDateTime parameter?
Why function from unit DateUtils cannot be used?
Code: Pascal  [Select][+][-]
  1. DateUtils.DecodeDateTime(StrToDateTime(strDateTime),
  2.   AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond)

ADiV

  • Jr. Member
  • **
  • Posts: 90
    • ADiV Software
Re: Suggestion for "jForms" "GetDateTimeDecode"
« Reply #2 on: October 20, 2018, 12:56:12 pm »
Which format is used for strDateTime parameter?
Why function from unit DateUtils cannot be used?
Code: Pascal  [Select][+][-]
  1. DateUtils.DecodeDateTime(StrToDateTime(strDateTime),
  2.   AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond)

This function is not compatible with "GetDateTime" of jForm since it uses the format 'yyyy-mm-dd hh:mm:ss' for example '2018-10-20 12:45:33'
« Last Edit: October 20, 2018, 12:58:45 pm by TR3E »

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Suggestion for "jForms" "GetDateTimeDecode"
« Reply #3 on: October 20, 2018, 01:21:46 pm »
This function is not compatible with "GetDateTime" of jForm since it uses the format 'yyyy-mm-dd hh:mm:ss' for example '2018-10-20 12:45:33'
Doesn't it contain an overload with TFormatsettings? Then it IS compatible. Also, the above is the logical format. I will have a look.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
Re: Suggestion for "jForms" "GetDateTimeDecode"
« Reply #4 on: October 20, 2018, 01:22:50 pm »
This function is not compatible with "GetDateTime" of jForm since it uses the format 'yyyy-mm-dd hh:mm:ss' for example '2018-10-20 12:45:33'

If you are using FPC 3.1+ add the clocale unit to your project, the date/time format in FPC should be correct for the current regional settings of the device.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Suggestion for "jForms" "GetDateTimeDecode"
« Reply #5 on: October 20, 2018, 01:29:18 pm »
This function is not compatible with "GetDateTime" of jForm since it uses the format 'yyyy-mm-dd hh:mm:ss' for example '2018-10-20 12:45:33'

If you are using FPC 3.1+ add the clocale unit to your project, the date/time format in FPC should be correct for the current regional settings of the device.
Indeed, but I just saw dateutil needs some work regarding Tformatsettings overloads (sysutils is completely done).
IMHO it should be fixed like that.
« Last Edit: October 20, 2018, 01:31:02 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018