StoneKit.Core.Structs.Age 2024.1.1.391401

dotnet add package StoneKit.Core.Structs.Age --version 2024.1.1.391401                
NuGet\Install-Package StoneKit.Core.Structs.Age -Version 2024.1.1.391401                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StoneKit.Core.Structs.Age" Version="2024.1.1.391401" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StoneKit.Core.Structs.Age --version 2024.1.1.391401                
#r "nuget: StoneKit.Core.Structs.Age, 2024.1.1.391401"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StoneKit.Core.Structs.Age as a Cake Addin
#addin nuget:?package=StoneKit.Core.Structs.Age&version=2024.1.1.391401

// Install StoneKit.Core.Structs.Age as a Cake Tool
#tool nuget:?package=StoneKit.Core.Structs.Age&version=2024.1.1.391401                

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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 92 10/5/2024
2024.1.1.305385 71 8/5/2024
2024.1.1.268769 105 7/9/2024
2024.1.1.261673 107 7/4/2024
2024.1.1.261665 101 7/4/2024
2024.1.1.261631 100 7/4/2024
2024.1.1.260673 108 7/3/2024
2024.1.1.260489 98 7/3/2024
2024.1.1.260485 101 7/3/2024
1.24.703.180756 112 7/3/2024
1.24.703.164608 101 7/3/2024
1.24.703.121206 113 7/3/2024
1.24.626.192706 112 6/26/2024
1.24.612.859 102 6/11/2024
1.24.611.233127 111 6/11/2024
1.24.611.232756 93 6/11/2024
1.24.603.121931 92 6/3/2024