StoneKit.Core.Structs.Age
2024.1.1.305385
dotnet add package StoneKit.Core.Structs.Age --version 2024.1.1.305385
NuGet\Install-Package StoneKit.Core.Structs.Age -Version 2024.1.1.305385
<PackageReference Include="StoneKit.Core.Structs.Age" Version="2024.1.1.305385" />
paket add StoneKit.Core.Structs.Age --version 2024.1.1.305385
#r "nuget: StoneKit.Core.Structs.Age, 2024.1.1.305385"
// Install StoneKit.Core.Structs.Age as a Cake Addin #addin nuget:?package=StoneKit.Core.Structs.Age&version=2024.1.1.305385 // Install StoneKit.Core.Structs.Age as a Cake Tool #tool nuget:?package=StoneKit.Core.Structs.Age&version=2024.1.1.305385
Age Struct
Age Struct is a lightweight C# library that provides a struct representing age in years and days, along with various extension methods for calculating and determining age based on a given date.
Installation
You can install Age Struct via NuGet Package Manager:
PM> Install-Package StoneKit.Core.Structs.Age
Usage
Age Struct
The Age
struct represents an age in years and days, providing properties for the number of years and days, and some predefined age limits for infants, children, and adults.
using System;
// Create an Age instance
var age = new Age(5, 200);
// Access years and days
Console.WriteLine($"Years: {age.Years}, Days: {age.Days}");
// Use predefined age limits
var minAdultAge = Age.MinAgeAdult;
var maxChildAge = Age.MaxAgeChild;
var maxInfantAge = Age.MaxAgeInfant;
Extension Methods
The library provides a set of extension methods for DateTime
to calculate and determine age.
using System;
// Calculate age based on birth date
DateTime birthday = new DateTime(2015, 6, 15);
Age age = birthday.GetAge();
Console.WriteLine($"Age: {age.Years} years, {age.Days} days");
// Calculate age based on birth date and a specific date
DateTime referenceDate = new DateTime(2024, 6, 1);
Age ageOnReferenceDate = birthday.GetAge(referenceDate);
Console.WriteLine($"Age on {referenceDate.ToShortDateString()}: {ageOnReferenceDate.Years} years, {ageOnReferenceDate.Days} days");
// Determine if a person is an infant
bool isInfant = birthday.IsInfant();
Console.WriteLine($"Is infant: {isInfant}");
// Determine if a person is a child
bool isChild = birthday.IsChild();
Console.WriteLine($"Is child: {isChild}");
// Determine if a person is an adult
bool isAdult = birthday.IsAdult();
Console.WriteLine($"Is adult: {isAdult}");
Features
- Age Struct: Represents an age in years and days with predefined limits for infants, children, and adults.
- Extension Methods: Provides a set of extension methods for
DateTime
to:GetAge()
: Calculate age based on birth date.IsInfant()
: Determine if a person is an infant.IsChild()
: Determine if a person is a child.IsAdult()
: Determine if a person is an adult.
Contributions
Contributions and feedback are welcome! Feel free to submit issues, feature requests, or pull requests on the GitHub repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2024.1.1.305385 | 31 | 8/5/2024 |
2024.1.1.268769 | 63 | 7/9/2024 |
2024.1.1.261673 | 73 | 7/4/2024 |
2024.1.1.261665 | 68 | 7/4/2024 |
2024.1.1.261631 | 68 | 7/4/2024 |
2024.1.1.260673 | 70 | 7/3/2024 |
2024.1.1.260489 | 66 | 7/3/2024 |
2024.1.1.260485 | 73 | 7/3/2024 |
1.24.703.180756 | 79 | 7/3/2024 |
1.24.703.164608 | 69 | 7/3/2024 |
1.24.703.121206 | 67 | 7/3/2024 |
1.24.626.192706 | 75 | 6/26/2024 |
1.24.612.859 | 71 | 6/11/2024 |
1.24.611.233127 | 81 | 6/11/2024 |
1.24.611.232756 | 67 | 6/11/2024 |
1.24.603.121931 | 60 | 6/3/2024 |