Constellation class (userlib.world.time.constellation)

xiaoxiao2021-03-31  212

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

///

Public Class Constellation

{

Private static segment [] data = new segment [12]; // Save the constellation data

///

/// Date index function

///

/// Date

/// Corresponding index

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

///

/// Chinese name

/// Corresponding index

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

///

/// English name

/// Corresponding index

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

///

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

///

/// Date

/// Constellation Chinese name

Public Static String getcnname (DateTime DT)

{

INT I = Index (DT);

Return Data [i] .cnname

}

///

/// Get an English name of the constellation

///

/// Date

/// Scripsy English name

Public Static String Getenname (DateTime DT)

{

INT i = index (dt); return data [i] .enname;

}

///

/// Get the start date of the constellation

///

/// Chinese name

/// Constellation start date

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

///

/// Chinese name

/// termination date of the constellation

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

///

/// English name

/// Constellation start date

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

///

/// English name

/// termination date of the constellation

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

///

/// Date

/// Constellation start date

Public Static DateTime GetStartDateBydate (DateTime DT)

{

INT I = Index (DT);

Return Data [i] .startdatetime;

}

///

/// Get the termination date of the constellation

///

/// Date

/// termination date of the constellation

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

///

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

///

/// Chinese name

/// Chinese name abbreviation

/// English name

/// English name abbreviation

/// Start date

/// Termination date

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

///

PUBLIC segment () {}

///

/// Constructor

///

/// Chinese name /// time

Public segment (String CNName, DateTime DateTime)

{

Evaluate (CNName, NULL, NULL, NULL, DATETIME, DATETIME);

}

///

/// Constructor

///

/// Chinese name

/// English name

/// Time

Public segment (string cnname, string enname, datetime datetime)

{

Evaluate (CNName, NULL, Enname, NULL, DATETIME, DATETIME);

}

///

/// Constructor

///

/// Chinese name

/// Chinese name abbreviation

/// English name

/// English name abbreviation

/// Time

Public segment (string cnname, string cnshortname, string enname, string enshortname, datetime datetime)

{

Evaluate (CNName, CNSHORTNAME, Enname, EnshortName, DateTime, DateTime);

}

///

/// Constructor

///

/// Chinese name

/// Start date

/// Termination date

Public segment (string cnname, datetime startdatetime, datetime enddatetime)

{

Evaluate (CNName, NULL, NULL, NULL, STARTDATIME, ENDDATETIME);

}

///

/// Constructor

///

/// Chinese name

/// English name /// Start date

/// Termination date

Public segment (String CNName, String Enname, DateTime StartDatetime, DateTime EnddateTime)

{

Evaluate (CNName, NULL, Enname, NULL, STARTDATETIME, ENDDATETIME);

}

///

/// Constructor

///

/// Chinese name

/// Chinese name abbreviation

/// English name

/// English name abbreviation

/// Start date

/// Termination date

Public segment (string cnname, string cnshortname)

{

Evaluate (CNSHORTNAME, CNSHORTNAME, Enname, EnshortName, StartDateTime, EnddateTime);

}

#ndregion

#region attribute

///

/// Get or set the Chinese name

///

Public String CNNAME

{

get

{

Return CNNAME;

}

set

{

CNNAME = VALUE;

}

}

///

/// Get or set Chinese name abbreviation

///

Public String Cnshortname

{

get

{

Return CNSHORTNAME;

}

set

{

CnShortName = VALUE;

}

}

///

/// Get or set an English name

///

Public String Enname

{

get

{

Return Enname;

}

set

{

Enname = value;

}

}

///

/// Get or set an English name abbreviation

///

Public String Enshortname

{

get

{

Return EnshortName;

}

set

{

ENSHORTNAME = VALUE;

}

}

///

/// Get or set the start time

///

Public datetime startdatetime {

get

{

Return Start;

}

set

{

START = VALUE;

}

}

///

/// Get or set the end time

///

Public DateTime EnddateTime

{

get

{

Return End;

}

set

{

End = value;

}

}

#ndregion

}

}

转载请注明原文地址:https://www.9cbs.com/read-130852.html

New Post(0)