The following is a constellation class, which is used to determine which constellation you belong to, or get the constellation corresponding to the date range.
The segments involved in it will explain in the end of the article.
Using system;
Using system.collections.Generic;
Using system.text;
Namespace Userlib.World.Time
{
///
/// Constellation
/// summary>
Public Class Constellation
{
Private static segment [] data = new segment [12]; // Save the constellation data
///
/// Date index function
/// summary>
/// Date param>
///
Private Static Int Index (DateTime DT)
{
// will be unified in the year
// Because the year is a leap year, when the date is the month, the program will not be wrong.
DateTime RDT = New DateTime (2000, DT.MONTH, DT.DAY);
For (int i = 0; i <12; i )
{
IF (RDT> = DATA [I] .startdatetime && rd <= data [i] .enddatetime)
{
Return I;
}
}
Return -1;
}
///
/// Chinese name index function
/// summary>
/// Chinese name param>
///
Private static int indexcn (String cnname)
{
For (int i = 0; i <12; i )
{
IF (Data [i] .cnname == cnname)
{
Return I;
}
}
Return -1;
}
///
/// English name index function
/// summary>
/// English name param>
///
Private static int indexen (String Enname)
{
For (int i = 0; i <12; i )
{
IF (data [i] .enname.tolower () == Enname.tolower ())
{
Return I;
}
}
Return -1;
}
///
/// Constructor
/// summary>
Static constellation ()
{
Data [0] = New Segment ("Aquarius", "Aquarius", New DateTime (2000, 1, 21), New DateTime (2000, 2, 18));
Data [1] = New Segment ("Pisces", "Pisces", New DateTime (2000, 2, 19), New DateTime (2000, 3, 20)); DATA [2] = New Segment ("Aries", " Aries ", New DateTime (2000, 3, 21), New DateTime (2000, 4, 20));
Data [3] = New Segment ("Taurus", "Taurus", New DateTime (2000, 4, 21), New DateTime (2000, 5, 21);
Data [4] = New Segment ("Double Subside", "Gemini", New DateTime (2000, 5, 22), New DateTime (2000, 6, 21);
Data [5] = New Segment ("Cancer", "Cancer", New DateTime (2000, 6, 22), New DateTime (2000, 7, 22));
Data [6] = New Segment ("Leo", "Leo", New DateTime (2000, 7, 23), New DateTime (2000, 8, 23));
Data [7] = New Segment ("Virgo", "Virgo", New DateTime (2000, 8, 24), New DateTime (2000, 9, 22));
Data [8] = New Segment ("Libra", "Libra", New DateTime (2000, 9, 23), New DateTime (2000, 10, 23));
Data [9] = New Segment ("Scorpio", "Scorpio", New DateTime (2000, 10, 24), New DateTime (2000, 11, 22));
Data [10] = New Segment ("Shot", "Sagittarius", New DateTime (2000, 11, 23), New DateTime (2000, 12, 21));
Data [11] = New segment ("Capricorn", "Capricorn", New DateTime (2000, 12, 22), New DateTime (2000, 1, 20));
}
///
/// Get the Chinese name of the constellation
/// summary>
/// Date param>
///
Public Static String getcnname (DateTime DT)
{
INT I = Index (DT);
Return Data [i] .cnname
}
///
/// Get an English name of the constellation
/// summary>
/// Date param>
///
Public Static String Getenname (DateTime DT)
{
INT i = index (dt); return data [i] .enname;
}
///
/// Get the start date of the constellation
/// summary>
/// Chinese name param>
///
Public Static DateTime getStartDateBycnname (String cnname)
{
INT i = indexcn (cnname);
IF (i! = -1)
{
Return Data [i] .startdatetime;
}
Else
{
Throw new indexoutofrangeexception ();
}
}
///
/// Get the termination date of the constellation
/// summary>
/// Chinese name param>
///
Public Static DateTime GetenddateBycnname (String CNName)
{
INT i = indexcn (cnname);
IF (i! = -1)
{
Return Data [i] .nddatetime;
}
Else
{
Throw new indexoutofrangeexception ();
}
}
///
/// Get the start date of the constellation
/// summary>
/// English name param>
///
Public Static DateTime GetStartDateByenname (String Enname)
{
INT I = Indexen (Enname);
IF (i! = -1)
{
Return Data [i] .startdatetime;
}
Else
{
Throw new indexoutofrangeexception ();
}
}
///
/// Get the termination date of the constellation
/// summary>
/// English name param>
///
Public Static DateTime GetenddateByenname (String Enname)
{
INT I = Indexen (Enname);
IF (i! = -1)
{
Return Data [i] .nddatetime;
}
Else
{
Throw new indexoutofrangeexception ();
}
}
///
/// Get the start date of the constellation
/// summary>
/// Date param>
///
Public Static DateTime GetStartDateBydate (DateTime DT)
{
INT I = Index (DT);
Return Data [i] .startdatetime;
}
///
/// Get the termination date of the constellation
/// summary>
/// Date param>
///
Public Static DateTime GetenddateByDate (DateTime DT)
{
INT I = Index (DT);
Return Data [i] .nddatetime;
}
}
}
The segment class mentioned above will be explained below.
This class is used to save each time corresponding to the meaning or festival name, in the constellation class for saving each constellation time period.
Using system;
Using system.collections.Generic;
Using system.text;
Namespace Userlib.World.Time
{
///
// Used to store the meaning of a time break
/// summary>
Public Class Segment
{
Private string cnname; // Chinese name
Private string cnshortname; // Chinese name abbreviation
Private string enname; // English name
PRIVATE STRING ENSHORTNAME; // English name abbreviation
Private datetime start; // start time
Private datetime end; // termination time
///
// / assignment function
/// summary>
/// Chinese name param>
/// Chinese name abbreviation param>
/// English name param>
/// English name abbreviation param>
/// Start date param>
/// Termination date param>
Private Void Evaluate (String Cnname, String Cnsh, String EnshortName, DateTime StartDateTime, DateTime EnddateTime)
{
THIS.CNNAME = CNNAME;
this.cnshortname = cnshortname;
this.enname = enname;
THIS.ENSHORTNAME = ENSHORTNAME;
START = STARTDATETIME;
End = enddatetime;
}
#REGION constructor
///
/// Constructor
/// summary>
PUBLIC segment () {}
///
/// Constructor
/// summary>
/// Chinese name param> /// time param>
Public segment (String CNName, DateTime DateTime)
{
Evaluate (CNName, NULL, NULL, NULL, DATETIME, DATETIME);
}
///
/// Constructor
/// summary>
/// Chinese name param>
/// English name param>
/// Time param>
Public segment (string cnname, string enname, datetime datetime)
{
Evaluate (CNName, NULL, Enname, NULL, DATETIME, DATETIME);
}
///
/// Constructor
/// summary>
/// Chinese name param>
/// Chinese name abbreviation param>
/// English name param>
/// English name abbreviation param>
/// Time param>
Public segment (string cnname, string cnshortname, string enname, string enshortname, datetime datetime)
{
Evaluate (CNName, CNSHORTNAME, Enname, EnshortName, DateTime, DateTime);
}
///
/// Constructor
/// summary>
/// Chinese name param>
/// Start date param>
/// Termination date param>
Public segment (string cnname, datetime startdatetime, datetime enddatetime)
{
Evaluate (CNName, NULL, NULL, NULL, STARTDATIME, ENDDATETIME);
}
///
/// Constructor
/// summary>
/// Chinese name param>
/// English name param> /// Start date param>
/// Termination date param>
Public segment (String CNName, String Enname, DateTime StartDatetime, DateTime EnddateTime)
{
Evaluate (CNName, NULL, Enname, NULL, STARTDATETIME, ENDDATETIME);
}
///
/// Constructor
/// summary>
/// Chinese name param>
/// Chinese name abbreviation param>
/// English name param>
/// English name abbreviation param>
/// Start date param>
/// Termination date param>
Public segment (string cnname, string cnshortname)
{
Evaluate (CNSHORTNAME, CNSHORTNAME, Enname, EnshortName, StartDateTime, EnddateTime);
}
#ndregion
#region attribute
///
/// Get or set the Chinese name
/// summary>
Public String CNNAME
{
get
{
Return CNNAME;
}
set
{
CNNAME = VALUE;
}
}
///
/// Get or set Chinese name abbreviation
/// summary>
Public String Cnshortname
{
get
{
Return CNSHORTNAME;
}
set
{
CnShortName = VALUE;
}
}
///
/// Get or set an English name
/// summary>
Public String Enname
{
get
{
Return Enname;
}
set
{
Enname = value;
}
}
///
/// Get or set an English name abbreviation
/// summary>
Public String Enshortname
{
get
{
Return EnshortName;
}
set
{
ENSHORTNAME = VALUE;
}
}
///
/// Get or set the start time
/// summary>
Public datetime startdatetime {
get
{
Return Start;
}
set
{
START = VALUE;
}
}
///
/// Get or set the end time
/// summary>
Public DateTime EnddateTime
{
get
{
Return End;
}
set
{
End = value;
}
}
#ndregion
}
}