SlugEnt.TimeUnit
2.10.0
See the version list below for details.
dotnet add package SlugEnt.TimeUnit --version 2.10.0
NuGet\Install-Package SlugEnt.TimeUnit -Version 2.10.0
<PackageReference Include="SlugEnt.TimeUnit" Version="2.10.0" />
<PackageVersion Include="SlugEnt.TimeUnit" Version="2.10.0" />
<PackageReference Include="SlugEnt.TimeUnit" />
paket add SlugEnt.TimeUnit --version 2.10.0
#r "nuget: SlugEnt.TimeUnit, 2.10.0"
#:package SlugEnt.TimeUnit@2.10.0
#addin nuget:?package=SlugEnt.TimeUnit&version=2.10.0
#tool nuget:?package=SlugEnt.TimeUnit&version=2.10.0
TimeUnit
The TimeUnit class is a C# immutable class (really a struct) that represents a time duration in a condensed form. Examples are: 65S = 65 milli-seconds 240s = 240 seconds 6m = 6 Minutes 3h = 3 hours 18d = 18 days 7w = 7 weeks
TimeUnits are valid between 0 mill-seconds and the max long weeks.
The max supported time unit type is weeks. The reason is that months are not a precise time period, some months have 30 days, some 31 days, some less. So the conversion from a week or seconds to a month will never be precise, so at the moment we stop at weeks.
TimeUnit Types
TimeUnit supports the following unit types: milliseconds seconds minutes hours days weeks
TimeUnit only supports positive values.
The class provides many methods of being able to convert the stored value into other values such as converting hours to minutes or seconds.
Usage
#!CSharp
// The following are all valid ways of defining a TimeUnit that is 10 minutes.
TimeUnit t1 = new TimeUnit("10m");
TimeUnit t1 = new TimeUnit("600s");
TimeUnit t1 = new TimeUnit(600000);
TimeUnit t1 = 600000;
TimeUnit t1 = "10m";
The following are some of the ways to extract information out of the TimeUnit class.
#!CSharp
TimeUnit t1 = new TimeUnit("10m");
// string s1 will be 10m
string s1 = t1;
// integer i1 will be 600000
int i1 = t1;
// st2 will be 90m (90 minutes).
// ValueAsWholeNumber returns the largest unit that can be represent the TimeUnit as a whole number.
TimeUnit t2 = new TimeUnit (5400000);
string st2 = t2.ValueAsWholeNumber;
// Print as a string
st2.ToString; // Produces 90 Minutes
// Print as its initial value:
TimeUnit t3 = "90m"
t3.Value; // Produces 90m
// st3 will be 5399 milliseconds as it cannot be converted to a whole number any larger.
TimeUnit t4 = new TimeUnit (5399);
string st4 = t4.ValueAsWholeNumber;
// Return just the numeric part of the TimeUnit.
// valA will be 19.
TimeUnit tA = "19d";
double valA = TA.ValueAsNumeric;
### TimeUnit Math!
The TimeUnit class supports math functions.
// Add 60minutes to DateTime object
TimeUnit t1 = "60m";
DateTime current = DateTime.Now;
DateTime future60m = t1.AddToDate(current);
// Add 2 TimeUnits together
TimeUnit a = new TimeUnit("59m");
TimeUnit b = "60s";
TimeUnit c = a + b;
C.ToString; // 1 Hour
// Subtract 2 TimeUnits. If the result is less than zero, then result is zero.
TimeUnit a = "12m";
TimeUnit b = "10m";
TimeUnit c = a - b;
C.ToString; // 2 Minutes
// All Math comparison operators are supported
// !=
// ==
// <
// >
// <=
// >=
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on SlugEnt.TimeUnit:
| Package | Downloads |
|---|---|
|
SlugEnt.VaultAgent
A C# library for interacting with HashiCorp's Vault. Supports Vault thru 1.16.0. .NetCore 8. |
|
|
SlugEnt.SemVerUtil
Package Description |
|
|
SlugEnt.ProcessQueueManager
Provides multithreading task scheduling components |
|
|
ProcessQueueManager
Provides multithreading task scheduling components |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.10.1 | 37 | 5/26/2026 |
| 2.10.0 | 39 | 5/26/2026 |
| 2.0.0 | 1,747 | 7/5/2021 |
| 1.4.0 | 565 | 6/4/2021 |
| 1.3.1 | 589 | 2/6/2021 |
| 1.3.0 | 633 | 12/13/2020 |
| 1.2.0 | 2,071 | 11/29/2020 |
| 1.2.0-NukeBuild0006 | 633 | 11/29/2020 |
| 1.2.0-nukebuild0005 | 526 | 11/22/2020 |
| 1.1.5 | 626 | 11/4/2020 |
| 1.1.5-alpha-1002 | 519 | 11/11/2020 |
| 1.1.5-alpha-1001 | 507 | 11/11/2020 |
| 1.1.4 | 659 | 11/4/2020 |
| 1.1.2 | 4,464 | 1/11/2019 |
| 1.1.1 | 1,250 | 1/11/2019 |
| 1.1.0 | 1,242 | 1/8/2019 |
| 1.0.0 | 1,203 | 1/5/2019 |
Net 10 release. No other changes