Good Morning!

I have a production application that must figure out whether 
Atlanta, GA is on DST or not.
This app was created to help me figure out an algorithm for this.

Included is the the text of the app. Just use them in a new project.

Or you can download the source and app from here:
www.GreatDayDan.com/TZTest.zip

You will need GpTimezone from ESBDates.

I would appreciate having someone look it over to see if I missed
something.

Thanks...Dan'l

{____________________________________________________________________}

program TZTest;
uses
  Forms,
  fTZTest in 'fTZTest.pas' {frmTZTest};
{$R *.res}
begin
  Application.Initialize;
  Application.CreateForm(TfrmTZTest, frmTZTest);
  Application.Run;
end.

{______________________________________________________________________________}
object frmTZTest: TfrmTZTest
  Left = 339
  Top = 172
  Width = 407
  Height = 391
  Caption = 'Select a Date'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object lbl7: TLabel
    Left = 48
    Top = 34
    Width = 69
    Height = 13
    Caption = 'Week off Year'
  end
  object lbl8: TLabel
    Left = 43
    Top = 58
    Width = 74
    Height = 13
    Caption = 'Week of Month'
  end
  object lblWoY: TLabel
    Left = 131
    Top = 34
    Width = 24
    Height = 13
    Caption = 'WoY'
  end
  object lblWoM: TLabel
    Left = 131
    Top = 58
    Width = 26
    Height = 13
    Caption = 'WoM'
  end
  object lbl9: TLabel
    Left = 54
    Top = 86
    Width = 63
    Height = 13
    Caption = 'Day of Week'
  end
  object lblDoW: TLabel
    Left = 131
    Top = 84
    Width = 25
    Height = 13
    Caption = 'DoW'
  end
  object lbl10: TLabel
    Left = 78
    Top = 120
    Width = 39
    Height = 13
    Caption = 'Is EDT?'
  end
  object lblIsEDT: TLabel
    Left = 131
    Top = 120
    Width = 30
    Height = 13
    Caption = 'IsEDT'
  end
  object Label1: TLabel
    Left = 71
    Top = 175
    Width = 46
    Height = 13
    Caption = 'nowLocal'
  end
  object lblnowLocal3: TLabel
    Left = 131
    Top = 175
    Width = 46
    Height = 13
    Caption = 'nowLocal'
  end
  object Label3: TLabel
    Left = 75
    Top = 199
    Width = 42
    Height = 13
    Caption = 'nowUTC'
  end
  object lblnowUTC3: TLabel
    Left = 131
    Top = 199
    Width = 42
    Height = 13
    Caption = 'nowUTC'
  end
  object Label9: TLabel
    Left = 73
    Top = 224
    Width = 44
    Height = 13
    Caption = 'ESTTime'
  end
  object lblEastern: TLabel
    Left = 131
    Top = 224
    Width = 62
    Height = 13
    Caption = 'Eastern Time'
  end
  object cal1: TMonthCalendar
    Left = 200
    Top = 8
    Width = 191
    Height = 154
    Date = 39819.8054572685
    TabOrder = 0
    OnClick = cal1Click
  end
  object jvclck1: TJvClock
    Left = 208
    Top = 174
    Width = 178
    Height = 41
    DateFormat = 'M/d/yyyy'
  end
  object mmo1: TMemo
    Left = 8
    Top = 248
    Width = 377
    Height = 89
    Lines.Strings = (
      'I have a producdtion application that must figure out whether '
      'Atlanta, GA is on DST or not.'
      
        'This app was created to help me figure out an algorythm for
this' +
        '.'
      ''
      'The rule for Daylight Savings is:'
      'Start: Second Sunday in March'
      'End: First Sunday in November'
      'Time: 2 am local time'
      ''
      'This app shows that this means that '
      'DST begins: week 10, day 7, at 2 AM'
      'DST ends   : week 44, day 7, at 2 AM'
      ''
      'This app shows that this is true for every year.'
      ''
      'Is this correct, or did I miss something?'
      ''
      'Please send comments to GreatDayDan @ Yahoo . com'
      ''
      'Thanks...')
    ScrollBars = ssVertical
    TabOrder = 2
  end
end


{______________________________________________________________________________}
unit fTZTest;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
  Dialogs, ComCtrls, StdCtrls, JvExComCtrls, JvDateTimePicker, Mask,
  ExtCtrls, JvExExtCtrls, JvComponent, JvClock, JvExtComponent;

type
  TfrmTZTest = class(TForm)
    lbl7: TLabel;
    lbl8: TLabel;
    lblWoY: TLabel;
    lblWoM: TLabel;
    lbl9: TLabel;
    lblDoW: TLabel;
    lbl10: TLabel;
    lblIsEDT: TLabel;
    cal1: TMonthCalendar;
    Label1: TLabel;
    lblnowLocal3: TLabel;
    Label3: TLabel;
    lblnowUTC3: TLabel;
    Label9: TLabel;
    lblEastern: TLabel;
    jvclck1: TJvClock;
    mmo1: TMemo;
    procedure cal1Click(Sender: TObject);
  private
    function GetWOY(const UTC: TDateTime): Integer;
    function GetWOM(const UTC: TDateTime): Integer;
    function GetDoW(const UTC: TDateTime): Integer;
    function EasternIsOnDST(const UTC: TDateTime): Boolean;
    function DSTStarted(const UTC: TDateTime): Boolean;
    function DSTEnded(const UTC: TDateTime): Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmTZTest: TfrmTZTest;

implementation
{$R *.dfm}
uses
  GpTimezone, DateUtils;



function TfrmTZTest.GetWOY(const UTC: TDateTime): Integer;
begin
  Result := WeekOfTheYear(utc);
end;

function TfrmTZTest.GetWOM(const UTC: TDateTime): Integer;
begin
  Result := WeekOfTheMonth(UTC);
end;

function TfrmTZTest.GetDoW(const UTC: TDateTime): Integer;
begin
  Result := DayOfTheWeek(UTC);
end;

function TfrmTZTest.EasternIsOnDST(const UTC: TDateTime): Boolean;
begin
  Result := DSTStarted(cal1.Date) and not DSTEnded(cal1.Date);
end;

function TfrmTZTest.DSTStarted(const UTC: TDateTime): Boolean;
begin
   Result := (GetWOY(UTC) > 10) or
             ((GetWOY(UTC) = 10) and
              (GetDoW(UTC) = 7 ) and
              (HourOf(Now) >= 2));
end;

function TfrmTZTest.DSTEnded(const UTC: TDateTime): Boolean;
begin
   Result := (GetWOY(UTC) > 44) or
             ((GetWOY(UTC) = 44) and
              (GetDoW(UTC) = 7 ) and
              (HourOf(Now) >= 2));
end;

procedure TfrmTZTest.cal1Click(Sender: TObject);
var
  tzi: TTimeZoneInformation;
  nowUTC, nowLocal, ESTTime: TDateTime;
  nowBias: integer;
  bEasternIsOnDST: Boolean;
begin
  nowLocal := (Now);
  bEasternIsOnDST := EasternIsOnDST(cal1.Date);
  GetNowUTCAndBias( nowUTC, nowBias);
  lblnowLOcal3.Caption := TimeToStr(nowLocal);
  lblnowUTC3.Caption := TimeToStr(nowUTC);

  lblWoY.Caption := IntToStr(GetWOY(cal1.Date));
  lblWoM.Caption := IntToStr(GetWOM(cal1.Date));
  lblDoW.Caption := IntToStr(GetDoW(cal1.Date));
  if bEasternIsOnDST then
    lblIsEDT.Caption := 'True'
  else
    lblIsEDT.Caption := 'False';

  if bEasternIsOnDST then
    lblEastern.Caption := TimeToStr(IncHour(nowUTC, -6))
  else
    lblEastern.Caption := TimeToStr(IncHour(nowUTC, -5));

end;

end.


Reply via email to