//
// Copyright (C) 2025 Sven Dmitrienko <svens@svens-tools.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
//
////////////////////////////////////////////////////////////////////////////////

unit sdDateUtils;

interface

type
  TSDDateUtils = class
  public
    class function ToYearMonthStr(const aDate: TDateTime): String;
    class function ToYearMonthDayStr(const aDate: TDateTime): String;
    class function ToYearMonthDayWeekdayStr(const aDate: TDateTime): String;
  end;

implementation

uses
  System.SysUtils, DateUtils, UnitMainForm;

class function TSDDateUtils.ToYearMonthStr(const aDate: TDateTime): String;
var
  a_MonthStr: String;
  a_SearchMonth: Byte;
  a_SearchYear: Integer;
begin
  a_SearchYear := YearOf(aDate);
  a_SearchMonth := MonthOf(aDate);
  if ( a_SearchMonth < 10 ) then
    a_MonthStr := '0' + IntToStr(a_SearchMonth)
  else
    a_MonthStr := IntToStr(a_SearchMonth);
  Result :=  IntToStr(a_SearchYear) + '-' + a_MonthStr;
end;

class function TSDDateUtils.ToYearMonthDayStr(const aDate: TDateTime): String;
var
  a_DayStr: String;
  a_MonthStr: String;
  a_SearchDay: Byte;
  a_SearchMonth: Byte;
  a_SearchYear: Integer;
begin
  a_SearchYear := YearOf(aDate);
  a_SearchMonth := MonthOf(aDate);
  if ( a_SearchMonth < 10 ) then
    a_MonthStr := '0' + IntToStr(a_SearchMonth)
  else
    a_MonthStr := IntToStr(a_SearchMonth);
  a_SearchDay := DayOf(aDate);
  if ( a_SearchDay < 10 ) then
    a_DayStr := '0' + IntToStr(a_SearchDay)
  else
    a_DayStr := IntToStr(a_SearchDay);
  Result := IntToStr(YearOf(aDate)) + '-' +
            a_MonthStr + '-' +
            a_DayStr;
end;

class function TSDDateUtils.ToYearMonthDayWeekdayStr(const aDate: TDateTime): String;
var
  a_Days: array[1..7] of string;
  a_DateStr: String;
begin
  a_DateStr := TSDDateUtils.ToYearMonthDayStr(aDate);
  a_Days[1] := 'Sunday';
  a_Days[2] := 'Monday';
  a_Days[3] := 'Tuesday';
  a_Days[4] := 'Wednesday';
  a_Days[5] := 'Thursday';
  a_Days[6] := 'Friday';
  a_Days[7] := 'Saturday';
  Result := a_DateStr + ' ' + a_Days[DayOfWeek(aDate)];
end;

end.
