Skip to content

BSL047 — Magic dates

Summary

Magic dates

Identifiers

Field Value
Rule code BSL047
Compatible alias MagicDate
Severity INFORMATION
Enabled by default Yes
Implemented Yes
Tags design, date-time

Behavior

  • The public identifier BSL047 and alias MagicDate are stable.
  • The rule reports the cases documented on this page.
  • Suppressions and project configuration are applied before publication.
  • The rule requires neither an external analyzer nor network access.

Configuration and suppression

BSL### is the primary stable identifier. The compatible alias is accepted in select, ignore, and compatible block suppression comments.

[tool.onec-hbk-bsl]
select = ["BSL047"]
ignore = ["MagicDate"]

All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:

  • noqa:
Value = "example";  // noqa: BSL047
  • bsl-disable:
Value = "example";  // bsl-disable: BSL047
  • compatible BSLLS form:
Value = "example";  // BSLLS:MagicDate-off

When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:

// noqa: BSL047
// code without this diagnostic
// noqa-enable: BSL047

// bsl-disable: BSL047
// code without this diagnostic
// bsl-enable: BSL047

// BSLLS:MagicDate-off
// code without this diagnostic
// BSLLS:MagicDate-on

To disable the rule until the end of the file, omit the closing noqa-enable, bsl-enable, or BSLLS:…-on marker.

Opening and closing markers must belong to the same family.

Description

Magic date is any date in your code that does not immediately become apparent without being immersed in context.

Examples

Bad

If now < '20151021' Then
    HoverBoardIsReal = Undefined;
EndIf;

Good

PredictedDate = '20151021';
If now < PredictedDate Then
    HoverBoardIsReal = Undefined;
EndIf;

Also, a good solution is to use a special method with "telling name" that returns constant

Function DateInventionHover()
    Return '20151021';
EndFunction

If CurrentDate < DateInventionHover() Then
    HoverBoardWillBeInvented = Undefined;
EndIf;

Exceptions

Magic dates used in structures and correspondences are not considered errors, as they are used as keys or values in data structures where the context is clear:

// Structure insert - no error
Structure = New Structure;
Structure.Insert("StartDate", '20250101'); // No error
Structure.Insert("EndDate", '20251231'); // No error
Structure.Insert("MaxDate", '39991231235959'); // No error

// Structure constructor - no error
Structure2 = New Structure("StartDate, EndDate", '20250101', '20251231'); // No error

// Direct structure property assignment - no error
StructureWithFields = New Structure("StartDate, EndDate");
StructureWithFields.StartDate = '20250101'; // No error
StructureWithFields.EndDate = '20251231'; // No error

// Fixed structure - no error
FixedStructure = New FixedStructure("Value", '20240101'); // No error

// Correspondence - no error (both key and value)
Correspondence = New Correspondence;
Correspondence.Insert("Code", '20230101'); // No error
Correspondence.Insert('19800101', "Olympics in Moscow"); // No error