StoneKit.Core.Structs.Age
1.24.703.121206
See the version list below for details.
dotnet add package StoneKit.Core.Structs.Age --version 1.24.703.121206
NuGet\Install-Package StoneKit.Core.Structs.Age -Version 1.24.703.121206
<PackageReference Include="StoneKit.Core.Structs.Age" Version="1.24.703.121206" />
paket add StoneKit.Core.Structs.Age --version 1.24.703.121206
#r "nuget: StoneKit.Core.Structs.Age, 1.24.703.121206"
// Install StoneKit.Core.Structs.Age as a Cake Addin #addin nuget:?package=StoneKit.Core.Structs.Age&version=1.24.703.121206 // Install StoneKit.Core.Structs.Age as a Cake Tool #tool nuget:?package=StoneKit.Core.Structs.Age&version=1.24.703.121206
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.391401 | 82 | 10/5/2024 |
2024.1.1.305385 | 66 | 8/5/2024 |
2024.1.1.268769 | 98 | 7/9/2024 |
2024.1.1.261673 | 98 | 7/4/2024 |
2024.1.1.261665 | 94 | 7/4/2024 |
2024.1.1.261631 | 93 | 7/4/2024 |
2024.1.1.260673 | 99 | 7/3/2024 |
2024.1.1.260489 | 92 | 7/3/2024 |
2024.1.1.260485 | 96 | 7/3/2024 |
1.24.703.180756 | 108 | 7/3/2024 |
1.24.703.164608 | 96 | 7/3/2024 |
1.24.703.121206 | 105 | 7/3/2024 |
1.24.626.192706 | 102 | 6/26/2024 |
1.24.612.859 | 98 | 6/11/2024 |
1.24.611.233127 | 106 | 6/11/2024 |
1.24.611.232756 | 88 | 6/11/2024 |
1.24.603.121931 | 86 | 6/3/2024 |