Support Board
Date/Time: Sun, 22 Jun 2025 15:57:51 +0000
Post From: ConvertDateTimeToChartTimeZone broken on daylight savings day when using SetTimeHMS
[2022-03-15 01:04:07] |
User719512 - Posts: 316 |
Here is a clean repro that you can run on this issue. Sierra Chart Engineering, please take a look and advise. Pacific Time/PT is 2 hours behind Chicago/Central Time/CT. So on a Chicago chart, 9am PT is 11 am CT. Using SetTime() for times before 10:00am give bad results on the DST day 3/13/2022. Using SetTime() for times on/after 10:00am give good results on the DST day 3/13/2022. This is running the same code. Sierra appears to be broken when using the pattern: sc.BaseDateTimeIn[sc.Index]; sc.ConvertDateTimeFromChartTimeZone(CurrentBarDateTime, TIMEZONE_LOS_ANGELES); SetTime() -> SetTime(Input_TimeOfDay.GetTime()); sc.ConvertDateTimeToChartTimeZone(PT_Time, TIMEZONE_LOS_ANGELES); The conversion FROM chart time and back TO chart time is not giving the same result on the DST day! One would expect a conversion FROM Central Time (chart time), TO Pacific Time, and back TO Central Time (Chart Time) to be equal. See output and a sample code below. You can repro this on a NQ 60 min chart set to Chicago time zone. -------------------------- Output -------------------------- Setting: Input_TimeOfDay -> 9:59 The time expected should all be "11:59:00". You can see for several bars, the time is "12:59:00". This is the issue. Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0049 @ 2022-03-11 14:30:00, PT_Time 2022-03-11 09:59:00 -> PT_to_CT_ChartTime 2022-03-11 11:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0050 @ 2022-03-11 15:15:00, PT_Time 2022-03-11 09:59:00 -> PT_to_CT_ChartTime 2022-03-11 11:59:00 | 2022-03-14 17:43:38.767 * --> error below Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0051 @ 2022-03-13 16:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0052 @ 2022-03-13 17:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0053 @ 2022-03-13 18:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0054 @ 2022-03-13 19:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0055 @ 2022-03-13 20:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0056 @ 2022-03-13 21:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0057 @ 2022-03-13 22:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0058 @ 2022-03-13 23:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0059 @ 2022-03-14 00:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0060 @ 2022-03-14 01:15:00, PT_Time 2022-03-13 09:59:00 -> PT_to_CT_ChartTime 2022-03-13 12:59:00 | 2022-03-14 17:43:38.767 * --> error above Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0061 @ 2022-03-14 02:15:00, PT_Time 2022-03-14 09:59:00 -> PT_to_CT_ChartTime 2022-03-14 11:59:00 | 2022-03-14 17:43:38.768 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0062 @ 2022-03-14 03:15:00, PT_Time 2022-03-14 09:59:00 -> PT_to_CT_ChartTime 2022-03-14 11:59:00 | 2022-03-14 17:43:38.768 * Setting: Input_TimeOfDay -> 10:00 Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0049 @ 2022-03-11 14:30:00, PT_Time 2022-03-11 10:00:00 -> PT_to_CT_ChartTime 2022-03-11 12:00:00 | 2022-03-14 17:45:23.345 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0050 @ 2022-03-11 15:15:00, PT_Time 2022-03-11 10:00:00 -> PT_to_CT_ChartTime 2022-03-11 12:00:00 | 2022-03-14 17:45:23.345 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0051 @ 2022-03-13 16:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.345 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0052 @ 2022-03-13 17:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.345 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0053 @ 2022-03-13 18:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.345 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0054 @ 2022-03-13 19:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.345 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0055 @ 2022-03-13 20:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.345 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0056 @ 2022-03-13 21:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.346 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0057 @ 2022-03-13 22:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.346 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0058 @ 2022-03-13 23:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.346 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0059 @ 2022-03-14 00:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.346 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0060 @ 2022-03-14 01:15:00, PT_Time 2022-03-13 10:00:00 -> PT_to_CT_ChartTime 2022-03-13 12:00:00 | 2022-03-14 17:45:23.346 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0061 @ 2022-03-14 02:15:00, PT_Time 2022-03-14 10:00:00 -> PT_to_CT_ChartTime 2022-03-14 12:00:00 | 2022-03-14 17:45:23.346 * Chart: F.US.ENQM22 [CBV][M] 60 Min #1 | Study: zzz_DST_Test | sc.Index: 0062 @ 2022-03-14 03:15:00, PT_Time 2022-03-14 10:00:00 -> PT_to_CT_ChartTime 2022-03-14 12:00:00 | 2022-03-14 17:45:23.346 * -------------------------- Code -------------------------- #include "sierrachart.h" // // scsf_DST_Test // SCSFExport scsf_DST_Test(SCStudyInterfaceRef sc) { SCInputRef Input_TimeOfDay = sc.Input[0]; if (sc.SetDefaults) { sc.GraphName = "zzz_DST_Test"; sc.AutoLoop = 1; sc.DrawZeros = 1; sc.GraphRegion = 1; sc.DrawStudyUnderneathMainPriceGraph = 0; Input_TimeOfDay.Name = "Time of Day PT"; Input_TimeOfDay.SetTime(HMS_TIME(6,30,0)); return; } if (sc.GetBarHasClosedStatus() != BHCS_BAR_HAS_CLOSED) { return; } SCDateTime CurrentBarDateTime = sc.BaseDateTimeIn[sc.Index]; SCDateTime CurrentBarDateTime_PT = sc.ConvertDateTimeFromChartTimeZone(CurrentBarDateTime, TIMEZONE_LOS_ANGELES); SCDateTime PT_Time = CurrentBarDateTime_PT; PT_Time.SetTime(Input_TimeOfDay.GetTime()); SCDateTime PT_to_CT_ChartTime = sc.ConvertDateTimeToChartTimeZone(PT_Time, TIMEZONE_LOS_ANGELES); SCString msg; msg.Format("sc.Index: %0.4d @ %s, PT_Time %s -> PT_to_CT_ChartTime %s", sc.Index, sc.FormatDateTime(CurrentBarDateTime).GetChars(), sc.FormatDateTime(PT_Time).GetChars(), sc.FormatDateTime(PT_to_CT_ChartTime).GetChars() ); sc.AddMessageToLog(msg, 1); } Date Time Of Last Edit: 2022-03-15 02:50:52
|