Line 480: |
Line 480: |
| SMAPI provides some C# objects you can use to simplify your code. | | SMAPI provides some C# objects you can use to simplify your code. |
| | | |
− | ===Semantic version=== | + | ===Dates=== |
| + | '''This is a proposed API that may be part of SMAPI 1.15. It's only available in preview versions of SMAPI and may change before release.''' |
| + | |
| + | Use <tt>SDate</tt> for calculating in-game dates. You start by creating a basic date: |
| + | <source lang="c#"> |
| + | // get the current date |
| + | var date = SDate.Now(); |
| + | |
| + | // get a date in the current year |
| + | var date = new SDate(30, "spring"); |
| + | |
| + | // get a date in the given year |
| + | var date = new SDate(30, "spring", 2); |
| + | </source> |
| + | |
| + | You can calculate offsets from any date: |
| + | <source lang="c#"> |
| + | // add days |
| + | new SDate(30, "spring", 1).AddDays(370); // 02 fall in year 4 |
| + | |
| + | // subtract days |
| + | new SDate(01, "spring", 2).AddDays(-1); // 30 winter in year 1 |
| + | </source> |
| + | |
| + | Note that <tt>SDate</tt> won't let you create invalid dates: |
| + | <source lang="C#"> |
| + | // ArgumentException: Invalid day '-1', must be a value from 0 to 30. |
| + | new Date(-1, "spring"); |
| + | |
| + | // ArithmeticException: Adding -1 days to 01 spring Y1 would result in invalid date 30 winter Y0. |
| + | new Date(1, "spring", 1).AddDays(-1); |
| + | </source> |
| + | |
| + | ===Semantic versions=== |
| Use <tt>SemanticVersion</tt> to manipulate and compare versions per the [http://semver.org/ Semantic Versioning 2.0 standard]. Example usage: | | Use <tt>SemanticVersion</tt> to manipulate and compare versions per the [http://semver.org/ Semantic Versioning 2.0 standard]. Example usage: |
| <source lang="c#"> | | <source lang="c#"> |