Azure.Maps.TimeZones 1.0.0-beta.1

Prefix Reserved
This is a prerelease version of Azure.Maps.TimeZones.
dotnet add package Azure.Maps.TimeZones --version 1.0.0-beta.1                
NuGet\Install-Package Azure.Maps.TimeZones -Version 1.0.0-beta.1                
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="Azure.Maps.TimeZones" Version="1.0.0-beta.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.Maps.TimeZones --version 1.0.0-beta.1                
#r "nuget: Azure.Maps.TimeZones, 1.0.0-beta.1"                
#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 Azure.Maps.TimeZones as a Cake Addin
#addin nuget:?package=Azure.Maps.TimeZones&version=1.0.0-beta.1&prerelease

// Install Azure.Maps.TimeZones as a Cake Tool
#tool nuget:?package=Azure.Maps.TimeZones&version=1.0.0-beta.1&prerelease                

Azure Maps TimeZone client library for .NET

Azure Maps TimeZone is a library which contains Azure Maps TimeZone APIs.

Source code | API reference documentation | REST API reference documentation | Product documentation

Getting started

Install the package

Install the client library for .NET with NuGet:

dotnet add package Azure.Maps.TimeZones --prerelease

Prerequisites

You must have an Azure subscription and Azure Maps account.

To create a new Azure Maps account, you can use the Azure Portal, Azure PowerShell, or the Azure CLI. Here's an example using the Azure CLI:

az maps account create --kind "Gen2" --account-name "myMapAccountName" --resource-group "<resource group>" --sku "G2"

Authenticate the client

There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra and Shared Access Signature (SAS) Authentication.

Shared Key authentication
  • Go to Azure Maps account > Authentication tab
  • Copy Primary Key or Secondary Key under Shared Key authentication section
// Create a MapsTimeZoneClient that will authenticate through Subscription Key (Shared key)
AzureKeyCredential credential = new AzureKeyCredential("<My Subscription Key>");
MapsTimeZoneClient client = new MapsTimeZoneClient(credential);
Microsoft Entra authentication

In order to interact with the Azure Maps service, you'll need to create an instance of the MapsTimeZoneClient class. The Azure Identity library makes it easy to add Microsoft Entra support for authenticating Azure SDK clients with their corresponding Azure services.

To use Microsoft Entra authentication, the environment variables as described in the Azure Identity README and create a DefaultAzureCredential instance to use with the MapsTimeZoneClient.

We also need an Azure Maps Client ID which can be found on the Azure Maps page > Authentication tab > "Client ID" in Microsoft Entra Authentication section.

// Create a MapsTimeZoneClient that will authenticate through MicrosoftEntra
DefaultAzureCredential credential = new DefaultAzureCredential();
string clientId = "<My Map Account Client Id>";
MapsTimeZoneClient client = new MapsTimeZoneClient(credential, clientId);
Shared Access Signature (SAS) Authentication

Shared access signature (SAS) tokens are authentication tokens created using the JSON Web token (JWT) format and are cryptographically signed to prove authentication for an application to the Azure Maps REST API.

Before integrating SAS token authentication, we need to install Azure.ResourceManager and Azure.ResourceManager.Maps (version 1.1.0 or higher):

dotnet add package Azure.ResourceManager
dotnet add package Azure.ResourceManager.Maps

And then we can get SAS token via List Sas API and assign it to MapsTimeZoneClient. In the follow code sample, we fetch a specific maps account resource, and create a SAS token for 1 day expiry time when the code is executed.

// Get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// Authenticate your client
ArmClient armClient = new ArmClient(cred);

string subscriptionId = "MyMapsSubscriptionId";
string resourceGroupName = "MyMapsResourceGroupName";
string accountName = "MyMapsAccountName";

// Get maps account resource
ResourceIdentifier mapsAccountResourceId = MapsAccountResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, accountName);
MapsAccountResource mapsAccount = armClient.GetMapsAccountResource(mapsAccountResourceId);

// Assign SAS token information
// Every time you want to SAS token, update the principal ID, max rate, start and expiry time
string principalId = "MyManagedIdentityObjectId";
int maxRatePerSecond = 500;

// Set start and expiry time for the SAS token in round-trip date/time format
DateTime now = DateTime.Now;
string start = now.ToString("O");
string expiry = now.AddDays(1).ToString("O");

MapsAccountSasContent sasContent = new MapsAccountSasContent(MapsSigningKey.PrimaryKey, principalId, maxRatePerSecond, start, expiry);
Response<MapsAccountSasToken> sas = mapsAccount.GetSas(sasContent);

// Create a MapsTimeZoneClient that will authenticate via SAS token
AzureSasCredential sasCredential = new AzureSasCredential(sas.Value.AccountSasToken);
MapsTimeZoneClient client = new MapsTimeZoneClient(sasCredential);

Key concepts

Thread safety

We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.

Additional concepts

Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime

Examples

You can familiarize yourself with different APIs using our samples.

Get TimeZone By ID

GetTimeZoneOptions options = new GetTimeZoneOptions()
{
    AdditionalTimeZoneReturnInformation = AdditionalTimeZoneReturnInformation.All
};
Response<TimeZoneResult> response = client.GetTimeZoneById("Asia/Bahrain", options);
Console.WriteLine("Version: " + response.Value.Version);
Console.WriteLine("Countires: " + response.Value.TimeZones[0].Countries);

Get TimeZone By Coordinates

GetTimeZoneOptions options = new GetTimeZoneOptions()
{
    AdditionalTimeZoneReturnInformation = AdditionalTimeZoneReturnInformation.All
};
GeoPosition coordinates = new GeoPosition(121.5640089, 25.0338053);
Response<TimeZoneResult> response = client.GetTimeZoneByCoordinates(coordinates, options);

Console.WriteLine("Time zone for (latitude, longitude) = ({0}, {1}) is {2}: ",
    coordinates.Latitude, coordinates.Longitude,
    response.Value.TimeZones[0].Name.Generic);

Get Windows TimeZone Ids

Response<WindowsTimeZoneData> response = client.GetWindowsTimeZoneIds();
Console.WriteLine("Total time zones: " + response.Value.WindowsTimeZones.Count);
foreach (WindowsTimeZone timeZone in response.Value.WindowsTimeZones)
{
    Console.WriteLine("IANA Id: " + timeZone.IanaIds);
    Console.WriteLine("Windows ID: " + timeZone.WindowsId);
    Console.WriteLine("Territory: " + timeZone.Territory);
}

Get Iana TimeZone Ids

Response<IanaIdData> response = client.GetTimeZoneIanaIds();
if (response.Value.IanaIds[0].AliasOf != null)
{
    Console.WriteLine("It is an alias: " + response.Value.IanaIds[0].AliasOf);
}
else
{
    Console.WriteLine("It is not an alias");
}
Console.WriteLine("IANA Id: " + response.Value.IanaIds[0].Id);

Get Iana Version

Response<TimeZoneIanaVersionResult> response = client.GetIanaVersion();
Console.WriteLine("IANA Version: " + response.Value.Version);

Convert Windows TimeZone To Iana

Response<IanaIdData> response = client.ConvertWindowsTimeZoneToIana("Dateline Standard Time");
Console.WriteLine("IANA Id: " + response.Value.IanaIds[0].Id);

Troubleshooting

General

When you interact with the Azure Maps services, errors returned by the service correspond to the same HTTP status codes returned for REST API requests.

For example, if you search with an invalid coordinate, a error is returned, indicating "Bad Request".

Next steps

Contributing

See the CONTRIBUTING.md for details on building, testing, and contributing to this library.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit <cla.microsoft.com>.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.0-beta.1 89 12/10/2024