Never stop learning, approaching the AI
  • 😄About
  • 🅰️AI-Candy on YouTube
    • 🎬YouTube 视频列表
    • 💠AI项目本地部署
      • 1️⃣安装 Pytorch 运行环境
      • 2️⃣在Python虚拟环境下使用 VS Code or PyCharm
        • VS Code Python format
      • 3️⃣Create python virtual environment in Linux
    • 👽AI 入门系列课程
      • 0️向量及向量运算
        • Reshape array code
      • 1️人工智能,机器学习,深度学习 和神经网络的区别
      • 2️卷积神经网络(CNN)
        • 3D CNN sample code
      • 3️Transformer 原理
      • 4️前馈神经网络 (FNN)
  • 🎭Artificial intelligence
    • 1️⃣Deep learning / machine learning
      • 👉Deep Learning Resources
      • 👉Deep learning notes
    • 2️⃣Python
      • Youtube音乐下载
      • Pytorch 安装环境配置 (old)
        • TorchEEG
      • Anaconda3 Python path
      • Data
      • IEEE-754 Floating Point Converter
        • ieee 754 conversion function
      • 文件读写
      • 文本清理
      • Python 下载在线视频
      • 修改Jupyter Notebook 默认工作目录
    • 3️⃣AI Websites
  • 🪤Programming
    • SQL
      • Delete data and reset auto-increment ID
    • Angular
      • Angular-datatables, dd/MM/yyyy, sorting (no paged list)
      • Datatables save state using localStorage
      • Variable storage method
      • Colour picker
      • Error fix for click columns on Datatable
      • Auto address use Google place
      • Auto address use Azure Maps
      • Upload file to Server
      • Validators.required OnChange input
      • Date, Time field
      • VS Code: Auto add missing imports when save
      • Datatable setting
      • Date time format
      • sticky <th> and <td> content
      • Filter booked time
      • Dropdown time selection with interval
      • Angular date online test
      • Updating data without refreshing the page
      • Object array sort and sum
      • Multi-type of columns use in one column
      • Select button for datatables
      • Switch button and event
      • Delete column from Array
      • Three-layer structure
      • Remove shadow when print mat-dialog content
      • JSON Parse && Object Array
      • Detect unused import in Typescript
      • Change location using radio button
      • display multi line message in the Toastr
      • Custom LOCALE_ID
      • Batch add data from csv to API server
        • Angular read csv and upload to Server
      • USB Port reader Web solution
      • Debug Angular app using JavaScript Debugger in VS Code
      • Skills
        • FormData & FormGroup to JSON
        • Dropdown list (customer)
        • Get current datetime
        • Get first day of year, month, and date
        • Call a function in a forEach loop
        • disable and readonly
        • Form element value
        • HTML input type
        • Input pattern (validation)
      • Display pipe (UI format)
        • Input upper case and button checked
        • Icons (Bootstrap and CoreUI)
        • Page Refresh
        • Selection list (two ways)
        • onChange Selection event
        • Random Password and Toggle
        • Password match
        • Select checkbox disable
      • Print and save to PDF
      • Import JS into Angular
      • LocalStorage
      • Angular DataTable
        • Data sort
        • A sample usage
        • Angular DataTable server side big data query
      • Change chart.js chart type
      • Angular UI - .NET API - .NET Auth
      • Angular - .NET API
      • *ngIf else && change to @if
      • Angular add reCAPTCHA v3 (Google)
      • Angular update
        • Update from v13 to v15
        • Update from v15 to v18
      • Angular application version central
      • Face detection
        • Face-api.js
      • Angular, Node version compatibility matrix
      • Clear cache
      • Angular oauth2 OIDC
      • Angular add header
    • .NET Skills
      • Add ID manually
      • Auto Mapping
        • Ignore Nesting
        • Startup setting
        • Datetime processing in AutoMapping
        • AutoMapper example
      • Validation filter
      • BaseController
      • Group by many
      • Database first, scaffold to class
      • Log setting and exception handler
      • Update appsetting.json value
      • Azure service bus message (queue)
      • Read appsetting.json value
      • Auth get user info by email
      • Azure Time zone
      • .NET API Add Service
      • Object comparison
      • Coravel Schedule
        • Read appsettings.json
      • .Net Core RDLC Report, Coravel and Email
      • Check Network and SQL server connections.
      • Datatime custom format
      • Many to Many EF
        • Many to Many CheckBox
      • PDFpig: Send Email with PDF attachment
      • .NET Core Middleware order
      • .NET API add Worker Service
      • .NET Router
      • Partial columns update
      • Add and Delete
      • 图片自适应宽度
      • ASP.NET Identity
      • Upload file to Azure
        • Upload file to Blob
      • Developer Guide
      • Code first one-many
      • ASP.NET MVC 5 Custom Error Page
      • VS can't debug
      • 通过邮编查 NSW COVID-19 感染人数
      • Jquery File Upload
      • Jquery Datepicker
      • ajax delete file from server
      • Autofac in MVC
      • Autofac in .NET Core
      • .NET Core
      • HTTP Return code
      • IdentityServer4
    • Power BI
      • Add parameter to PowerBI report
      • Convert UTC to Local time
      • Python in PowerBI
        • IEEE-754 conversion
      • PowerBI embed app - Server
      • PowerBI embed app - Client
        • Setting on portal
    • Azure service
      • Key Vault
      • Service bus - queue
      • Power Automate
      • Kusto Query Language
      • Azure Data Explorer
      • Reserved keyword on Azure Error
      • SQL Azure time convert
    • Azure blob
      • Azure blob setting
      • Display image from Blob
      • Upload image to Blob through .NET API
    • Html Bootstrap Icon, colour, size
      • Html spacing
      • Html text alignment
    • Video stream - JsMpeg
      • SSL - generate key
      • Client (SSL)
      • Websocket-Server (SSL)
      • Play RTSP video stream
    • ⏰Time Zone
      • datetime-local set date range
      • 🕐Get data by local time (UI, API)
      • 🕑Add offset hours for local UI and report
      • 🕒UTC time and Datetime convert
      • 🕓Angular - Timezone selection
      • 🕔Angular - Convert UTC to local time
      • 🕕C# Time Zone
  • >>>>>>>>>>>>>>>>>>>>>>>>>>>>
  • 🪜Apps and Skills
    • 1️Windows system app skills
      • Brother HL-2130 打印机 Toner 报警
      • VS Code 快捷键
      • Check SHA256 on windows
      • blob 视频下载
      • Photoshop 制作证件照片
      • 获取 Windows Key
      • 10进制36进制互转
      • Error when publish to Azure
      • Disable windows automatic update
      • Outlook setup for Yahoo Email
      • IIS setting
      • Windows 8/10, IIS Service
      • 安装程序出错 2052,2053 报警
      • 6 Yao Chinese UI
    • 2️Linux command
    • 3️Git command
    • 4️Bitbucket
    • 5️Gitbook Skills
    • 6️GitHub Desktop
    • 7️⃣EndNote
      • EndNote V21
      • Endnote使用技巧
      • 批量删除/修改Endnote 中 notes 栏内容
  • Android mobile connect PC
  • 💎USEFUL LINKS
    • 1️Coding websites
      • Website links
    • 2️Windows 平台工具,网站
    • 3️PotPlayer 设置
  • >>>>>>>>>>>>>>>>>>>>>>>>>>>>
  • 🚩Research >>EEG
    • 1️EEG基本知识的理论介绍
      • EEG 简介
      • EEG 的节律信号
      • EEG电极帽
      • EEG 伪迹
      • ERP 介绍
      • ERP 成分
      • EEG 数据分析软件
    • 2️LSL 应用
    • 3️EEG公开数据集汇总整理
    • 4️REDCap
      • Migration (Export & Import)
    • 5️⃣ScaneR
  • ☕Buy me a coffee
Powered by GitBook
On this page

Was this helpful?

  1. Programming
  2. .NET Skills

Azure Time zone

// Time Zone Service

  public class TimeZoneService : ITimeZoneService
  {

      private readonly ILogger<TimeZoneService> _logger;
      public TimeZoneService(ILogger<TimeZoneService> logger)
      {
          this._logger = logger;
      }

      [Obsolete]
      public string CurrentTimeZoneName()
      {
          return TimeZone.CurrentTimeZone.StandardName;
      }

      public List<string> GetSystemTimeZoneDisplayNameList()
      {
          var systemTimeZoneList = TimeZoneInfo.GetSystemTimeZones();
          var timezoneList = new List<string>();
          foreach (var systemTimeZone in systemTimeZoneList)
              timezoneList.Add(systemTimeZone.DisplayName + " - " + systemTimeZone.Id);

          return timezoneList;
      }


      [Obsolete]
      public List<string> GetCurrentTimeZoneInfoList(string settingTimeZone, string localTimeStr, string localTimezoneName)
      {
          DateTime timeUtc = DateTime.UtcNow;
          var list = new List<string>();

          // get current timezone name   -- Azure timezone: 'Coordinated Universal Time'
          string timeZoneName = CurrentTimeZoneName();
          string timezoneInfo = "(Server) Timezone: " + timeZoneName;
          list.Add(timezoneInfo);
          _logger.LogInformation(timezoneInfo);

          // get current (Server) time
          DateTime currenttime = DateTime.Now;
          string currentTimeInfo = "Current (Server) Time: " + currenttime.ToString("dd/MM/yyyy HH:mm:ss");
          list.Add(currentTimeInfo);
          _logger.LogInformation(currentTimeInfo);


          // get utc time 
          string utcTimeInfo = "UTC Time: " + timeUtc.ToString("dd/MM/yyyy HH:mm:ss");
          list.Add(utcTimeInfo);
          _logger.LogInformation(utcTimeInfo);


          // get local (UI) time
          DateTime localtime = DateTime.Now;
          if (localTimeStr != null)
              localtime = DateTime.Parse(localTimeStr);

          string localTimeInfo = "Local (UI) Time: " + localtime.ToString("dd/MM/yyyy HH:mm:ss");
          list.Add(localTimeInfo);
          _logger.LogInformation(localTimeInfo);

          // get timezone id by local timezone name
          string localTimezoneId = GetAustraliaCityTimeZoneIdByName(localTimezoneName);
          if (localTimezoneId != null)
          {
              TimeZoneInfo ltz = TimeZoneInfo.FindSystemTimeZoneById(localTimezoneId);

              // get local timezone offset hours
              TimeSpan localOffset = ltz.GetUtcOffset(localtime);
              string localOffsetHoursInfo = "Local Timezone Offset hours: " + localOffset.Hours.ToString();
              list.Add(localOffsetHoursInfo);
              _logger.LogInformation(localOffsetHoursInfo);
          }

          // local timezone city
          string city = GetAustraliaCityNameByTimezoneName(localTimezoneName);
          if (city != null)
          {
              string localCityInfo = "Local Timezone City: " + city;
              list.Add(localCityInfo);
              _logger.LogInformation(localCityInfo);
          }

          // get setting timezone and offset hours ----  "TimeZone": "AUS Eastern Standard Time",
          TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(settingTimeZone);
          DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, tzi);

          // setting timezone name
          string settingTimezone = "Setting Timezone: " + settingTimeZone;
          list.Add(settingTimezone);
          _logger.LogInformation(settingTimezone);


          // get setting timezone offset hours
          TimeSpan offset = tzi.GetUtcOffset(timeUtc);
          string settingOffsetHoursInfo = "Setting Timezone Offset hours: " + offset.Hours.ToString();
          list.Add(settingOffsetHoursInfo);
          _logger.LogInformation(settingOffsetHoursInfo);



          // get Sydney time
          string sydneytimeInfo = "Sydney Time: " + cstTime.ToString("dd/MM/yyyy HH:mm:ss");
          list.Add(sydneytimeInfo);
          _logger.LogInformation(sydneytimeInfo);


          return list;
      }

      public List<string> SystemTimeZoneNameList()
      {
          List<string> timeZoneNameList = new List<string>();
          var tzList = TimeZoneInfo.GetSystemTimeZones().ToList();

          foreach (var tz in tzList)
          {
              timeZoneNameList.Add(tz.StandardName);
          }
          return timeZoneNameList;
      }

      public List<string> SystemTimeZoneIDList()
      {
          List<string> timeZoneId = new List<string>();
          var tzList = TimeZoneInfo.GetSystemTimeZones().ToList();

          foreach (var tz in tzList)
          {
              timeZoneId.Add(tz.Id);
          }

          return timeZoneId;
      }


      [Obsolete]
      public int GetTimeZoneOffsetHours(string timeZoneId)
      {
          // timeZoneId == "AUS Eastern Standard Time";
          TimeZone localZone = TimeZone.CurrentTimeZone;
          DateTime currentDate = DateTime.Now;

          var localTime = localZone.ToLocalTime(currentDate);
          var utcTime = localZone.ToUniversalTime(currentDate);

          _logger.LogInformation($"location time: " + localTime.ToString("MM/dd/yyyy HH:mm:ss"));
          _logger.LogInformation($"utc time: " + utcTime.ToString("MM/dd/yyyy HH:mm:ss"));


          DateTime timeUtc = DateTime.UtcNow;

          //get current timezone name   -- Azure timezone: 'Coordinated Universal Time'
          string timeZoneName = CurrentTimeZoneName();

          _logger.LogInformation($"timezone: " + timeZoneName);

          if (timeZoneName != timeZoneId)
          {
              TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
              if (tzi != null)
              {
                  _logger.LogInformation($"find destination timezone!");

                  //convert UTC to destination timezone time
                  DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, tzi);

                  _logger.LogInformation($"sydney time: " + cstTime.ToString("MM/dd/yyyy HH:mm:ss"));

                  TimeSpan offset = tzi.GetUtcOffset(timeUtc);

                  _logger.LogInformation($"offset hours: " + offset.Hours.ToString());
                  return offset.Hours;
              }

          }
          return 0;
      }

      public int GetTimeZoneOffsetHoursByLocalTimezone(string localTimezoneName, string localTimeStr)
      {
          // get local (UI) time
          DateTime localtime = DateTime.Now;
          if (localTimeStr != null)
              localtime = DateTime.Parse(localTimeStr);

          // get timezone id by local timezone name
          string localTimezoneId = GetAustraliaCityTimeZoneIdByName(localTimezoneName);
          if (localTimezoneId != null)
          {
              TimeZoneInfo ltz = TimeZoneInfo.FindSystemTimeZoneById(localTimezoneId);

              // get local timezone offset hours
              TimeSpan localOffset = ltz.GetUtcOffset(localtime);
              _logger.LogInformation("Local Timezone Offset hours: " + localOffset.Hours.ToString());
              return localOffset.Hours;
          }
          return 0;
      }


      public string GetAustraliaCityTimeZoneIdByName(string timeZoneName)
      {
          var list = AustraliaTimeZoneList();

          //get .net timezone id by js timezone name
          var result = list.Where(x => x.Item1 == timeZoneName).FirstOrDefault();
          return result.Item3;
      }

      public string GetAustraliaCityNameByTimezoneName(string timeZoneName)
      {
          var list = AustraliaTimeZoneList();

          //get city name by js timezone name
          var result = list.Where(x => x.Item1 == timeZoneName).FirstOrDefault();
          return result.Item2;
      }

      public string GetTimeZoneById(string timeZoneId)
      {
          var list = timeZoneList();    // or SystemTimeZoneIDList();

          var result = list.Where(x => x.Item1 == timeZoneId).FirstOrDefault();
          return result.Item3;
      }

      #region cron


      public string GetHourTimeCronStr(int hour, int minute)
      {
          // Cron("0 1 * * *") >> run at 1:00 AM daily 

          var h = hour.ToString();
          if (h.Length == 1)
              h = "0" + h;

          var m = minute.ToString();
          if (m.Length == 1)
              m = "0" + m;

          return m + " " + h;
      }

      public string GetOffsetHourTimeCronStr(int hour, int minute, int offsetHours)
      {
          // 08:26 ==> '26 08'
          if (hour >= offsetHours)
              hour = hour - offsetHours;
          else
              hour = hour + 24 - offsetHours;

          var h = hour.ToString();
          if (h.Length == 1)
              h = "0" + h;

          var m = minute.ToString();
          if (m.Length == 1)
              m = "0" + m;

          string cronTimeStr = m + " " + h;

          return cronTimeStr;
      }

      #endregion


      #region appsetting

      public string GetAppSettingTimeZone(string sectionName)
      {
          var jsonStr = GetAppSettingJsonStr(sectionName);
          return (string)jsonStr["TimeZone"];
      }


      public JToken GetAppSettingJsonStr(string sectionName)
      {
          var path = Directory.GetCurrentDirectory();
          var filePath = Path.Combine(path, "appSettings.json");
          if (global::System.IO.File.Exists(filePath))
          {
              string json = global::System.IO.File.ReadAllText(filePath);
              var jsonStr = JObject.Parse(json)[sectionName];
              return jsonStr;
          }
          return null;
      }


      public string ReadAppSetting(string key, string value)
      {
          try
          {
              string newValue = value;
              var path = Directory.GetCurrentDirectory();
              var filePath = Path.Combine(path, "appSettings.json");
              if (global::System.IO.File.Exists(filePath))
              {
                  string json = global::System.IO.File.ReadAllText(filePath);
                  dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
                  var sectionPath = key.Split(":")[0];

                  if (!string.IsNullOrEmpty(sectionPath))
                  {
                      var keyPath = key.Split(":")[1];
                      newValue = jsonObj[sectionPath][keyPath];
                  }
              }
              return newValue;
          }
          catch (ConfigurationErrorsException)
          {
              Console.WriteLine("Error writing app settings");
              return null;
          }
      }



      public void UpdateAppSetting(string key, string value, string schedule)
      {
          switch (schedule)
          {
              case "monthly":
                  value = value + " 1 * *";
                  break;
              case "weekly":
                  value = value + " * * 1";
                  break;
              case "daily":
                  value = value + " * * *";
                  break;
              default:
                  break;
          }

          try
          {
              var path = Directory.GetCurrentDirectory();
              var filePath = Path.Combine(path, "appSettings.json");
              if (global::System.IO.File.Exists(filePath))
              {
                  string json = global::System.IO.File.ReadAllText(filePath);
                  dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
                  var sectionPath = key.Split(":")[0];
                  if (!string.IsNullOrEmpty(sectionPath))
                  {
                      var keyPath = key.Split(":")[1];
                      var oldvalue = jsonObj[sectionPath][keyPath];
                      jsonObj[sectionPath][keyPath] = value;
                  }
                  else
                  {
                      jsonObj[sectionPath] = value;
                  }
                  string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
                  global::System.IO.File.WriteAllText(filePath, output);
              }
          }
          catch (ConfigurationErrorsException)
          {
              _logger.LogInformation($"Error writing app settings");
              Console.WriteLine("Error writing app settings");
          }
      }

      #endregion

      private List<Tuple<string, string, string>> AustraliaTimeZoneList()
      {
          // JS name, JS City, .NET id
          var list = new List<Tuple<string, string, string>>{
              new Tuple<string,string,string>("Australian Western Standard Time", "Perth", "W. Australia Standard Time"),                     // +8
              new Tuple<string,string,string>("Australian Central Western Standard Time", "Eucla", "Aus Central W. Standard Time"),           // +8:45
              new Tuple<string,string,string>("Australian Central Standard Time", "Darwin", "AUS Central Standard Time"),                     // +9:30/+10:30
              new Tuple<string,string,string>("Australian Eastern Standard Time", "Brisbane", "E. Australia Standard Time"),                  // +10
              new Tuple<string,string,string>("Australian Central Daylight Time", "Adelaide", "Cen. Australia Standard Time"),                // +10:30
              new Tuple<string,string,string>("Australian Eastern Daylight Time", "Canberra/Sydney/Melbourne", "AUS Eastern Standard Time"),  // +11/+10
              new Tuple<string,string,string>("Lord Howe Daylight Time", "Lord Howe Island", "Lord Howe Standard Time")};                     // +11/+10

          return list;
      }


      private List<Tuple<string, string, string>> timeZoneList()
      {
          // .NET id, display-name
          var list = new List<Tuple<string, string, string>>{
                  new Tuple<string,string,string>("Dateline Standard Time", "(UTC-12:00)", "W. Australia Standard Time"),
                  new Tuple<string,string,string>("UTC-11", "(UTC-11:00)", "Coordinated Universal Time-11"),
                  new Tuple<string,string,string>("Aleutian Standard Time", "(UTC-10:00)", "Aleutian Islands"),
                  new Tuple<string,string,string>("Hawaiian Standard Time", "(UTC-10:00)", "Hawaii"),
                  new Tuple<string,string,string>("Marquesas Standard Time", "(UTC-09:30)", "Marquesas Islands"),
                  new Tuple<string,string,string>("Alaskan Standard Time", "(UTC-09:00)", "Alaska"),
                  new Tuple<string,string,string>("UTC-09", "(UTC-09:00)", "Coordinated Universal Time-09"),
                  new Tuple<string,string,string>("Pacific Standard Time (Mexico)", "(UTC-08:00)", "Baja California"),
                  new Tuple<string,string,string>("UTC-08", "(UTC-08:00)", "Coordinated Universal Time-08"),
                  new Tuple<string,string,string>("Pacific Standard Time", "(UTC-08:00)", "Pacific Time (US & Canada)"),
                  new Tuple<string,string,string>("US Mountain Standard Time", "(UTC-07:00)", "Arizona"),
                  new Tuple<string,string,string>("Mountain Standard Time (Mexico)", "(UTC-07:00)", "Chihuahua, La Paz, Mazatlan"),
                  new Tuple<string,string,string>("Mountain Standard Time", "(UTC-07:00)", "Mountain Time (US & Canada)"),
                  new Tuple<string,string,string>("Central America Standard Time", "(UTC-06:00)", "Central America"),
                  new Tuple<string,string,string>("Central Standard Time", "(UTC-06:00)", "Central Time (US & Canada)"),
                  new Tuple<string,string,string>("Easter Island Standard Time", "(UTC-06:00)", "Easter Island"),
                  new Tuple<string,string,string>("Central Standard Time (Mexico)", "(UTC-06:00)", "Guadalajara, Mexico City, Monterrey"),
                  new Tuple<string,string,string>("Canada Central Standard Time", "(UTC-06:00)", "Saskatchewan"),
                  new Tuple<string,string,string>("SA Pacific Standard Time", "(UTC-05:00)", "Bogota, Lima, Quito, Rio Branco"),
                  new Tuple<string,string,string>("Eastern Standard Time (Mexico)", "(UTC-05:00)", "Chetumal"),
                  new Tuple<string,string,string>("Eastern Standard Time", "(UTC-05:00)", "Eastern Time (US & Canada)"),
                  new Tuple<string,string,string>("Haiti Standard Time", "(UTC-05:00)", "Haiti"),
                  new Tuple<string,string,string>("Cuba Standard Time", "(UTC-05:00)", "Havana"),
                  new Tuple<string,string,string>("US Eastern Standard Time", "(UTC-05:00)", "Indiana (East)"),
                  new Tuple<string,string,string>("Turks And Caicos Standard Time", "(UTC-05:00)", "Turks and Caicos"),
                  new Tuple<string,string,string>("Paraguay Standard Time", "(UTC-04:00)", "Asuncion"),
                  new Tuple<string,string,string>("Atlantic Standard Time", "(UTC-04:00)", "Atlantic Time (Canada)"),
                  new Tuple<string,string,string>("Venezuela Standard Time", "(UTC-04:00)", "Caracas"),
                  new Tuple<string,string,string>("Central Brazilian Standard Time", "(UTC-04:00)", "Cuiaba"),
                  new Tuple<string,string,string>("SA Western Standard Time", "(UTC-04:00)", "Georgetown, La Paz, Manaus, San Juan"),
                  new Tuple<string,string,string>("Pacific SA Standard Time", "(UTC-04:00)", "Santiago"),
                  new Tuple<string,string,string>("Newfoundland Standard Time", "(UTC-03:30)", "Newfoundland"),
                  new Tuple<string,string,string>("Tocantins Standard Time", "(UTC-03:00)", "Araguaina"),
                  new Tuple<string,string,string>("E. South America Standard Time", "(UTC-03:00)", "Brasilia"),
                  new Tuple<string,string,string>("SA Eastern Standard Time", "(UTC-03:00)", "Cayenne, Fortaleza"),
                  new Tuple<string,string,string>("Argentina Standard Time", "(UTC-03:00)", "City of Buenos Aires"),
                  new Tuple<string,string,string>("Greenland Standard Time", "(UTC-03:00)", "Greenland"),
                  new Tuple<string,string,string>("Montevideo Standard Time", "(UTC-03:00)", "Montevideo"),
                  new Tuple<string,string,string>("Magallanes Standard Time", "(UTC-03:00)", "Punta Arenas"),
                  new Tuple<string,string,string>("Saint Pierre Standard Time", "(UTC-03:00)", "Saint Pierre and Miquelon"),
                  new Tuple<string,string,string>("Bahia Standard Time", "(UTC-03:00)", "Salvador"),
                  new Tuple<string,string,string>("UTC-02", "(UTC-02:00)", "Coordinated Universal Time-02"),
                  new Tuple<string,string,string>("Mid-Atlantic Standard Time", "(UTC-02:00)", "Mid-Atlantic - Old"),
                  new Tuple<string,string,string>("Azores Standard Time", "(UTC-01:00)", "Azores"),
                  new Tuple<string,string,string>("Cape Verde Standard Time", "(UTC-01:00)", "Cabo Verde Is."),
                  new Tuple<string,string,string>("UTC", "(UTC)", "Coordinated Universal Time"),
                  new Tuple<string,string,string>("GMT Standard Time", "(UTC+00:00)", "Dublin, Edinburgh, Lisbon, London"),
                  new Tuple<string,string,string>("Greenwich Standard Time", "(UTC+00:00)", "Monrovia, Reykjavik"),
                  new Tuple<string,string,string>("W. Europe Standard Time", "(UTC+01:00)", "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna"),
                  new Tuple<string,string,string>("Central Europe Standard Time", "(UTC+01:00)", "Belgrade, Bratislava, Budapest, Ljubljana, Prague"),
                  new Tuple<string,string,string>("Romance Standard Time", "(UTC+01:00)", "Brussels, Copenhagen, Madrid, Paris"),
                  new Tuple<string,string,string>("Morocco Standard Time", "(UTC+01:00)", "Casablanca"),
                  new Tuple<string,string,string>("Sao Tome Standard Time", "(UTC+01:00)", "Sao Tome"),
                  new Tuple<string,string,string>("Central European Standard Time", "(UTC+01:00)", "Sarajevo, Skopje, Warsaw, Zagreb"),
                  new Tuple<string,string,string>("W. Central Africa Standard Time", "(UTC+01:00)", "West Central Africa"),
                  new Tuple<string,string,string>("Jordan Standard Time", "(UTC+02:00)", "Amman"),
                  new Tuple<string,string,string>("GTB Standard Time", "(UTC+02:00)", "Athens, Bucharest"),
                  new Tuple<string,string,string>("Middle East Standard Time", "(UTC+02:00)", "Beirut"),
                  new Tuple<string,string,string>("Egypt Standard Time", "(UTC+02:00)", "Cairo"),
                  new Tuple<string,string,string>("E. Europe Standard Time", "(UTC+02:00)", "Chisinau"),
                  new Tuple<string,string,string>("Syria Standard Time", "(UTC+02:00)", "Damascus"),
                  new Tuple<string,string,string>("West Bank Standard Time", "(UTC+02:00)", "Gaza, Hebron"),
                  new Tuple<string,string,string>("South Africa Standard Time", "(UTC+02:00)", "Harare, Pretoria"),
                  new Tuple<string,string,string>("FLE Standard Time", "(UTC+02:00)", "Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius"),
                  new Tuple<string,string,string>("Israel Standard Time", "(UTC+02:00)", "Jerusalem"),
                  new Tuple<string,string,string>("Kaliningrad Standard Time", "(UTC+02:00)", "Kaliningrad"),
                  new Tuple<string,string,string>("Sudan Standard Time", "(UTC+02:00)", "Khartoum"),
                  new Tuple<string,string,string>("Libya Standard Time", "(UTC+02:00)", "Tripoli"),
                  new Tuple<string,string,string>("Namibia Standard Time", "(UTC+02:00)", "Windhoek"),
                  new Tuple<string,string,string>("Arabic Standard Time", "(UTC+03:00)", "Baghdad"),
                  new Tuple<string,string,string>("Turkey Standard Time", "(UTC+03:00)", "Istanbul"),
                  new Tuple<string,string,string>("Arab Standard Time", "(UTC+03:00)", "Kuwait, Riyadh"),
                  new Tuple<string,string,string>("Belarus Standard Time", "(UTC+03:00)", "Minsk"),
                  new Tuple<string,string,string>("Russian Standard Time", "(UTC+03:00)", "Moscow, St. Petersburg"),
                  new Tuple<string,string,string>("E. Africa Standard Time", "(UTC+03:00)", "Nairobi"),
                  new Tuple<string,string,string>("Iran Standard Time", "(UTC+03:30)", "Tehran"),
                  new Tuple<string,string,string>("Arabian Standard Time", "(UTC+04:00)", "Abu Dhabi, Muscat"),
                  new Tuple<string,string,string>("Astrakhan Standard Time", "(UTC+04:00)", "Astrakhan, Ulyanovsk"),
                  new Tuple<string,string,string>("Azerbaijan Standard Time", "(UTC+04:00)", "Baku"),
                  new Tuple<string,string,string>("Russia Time Zone 3", "(UTC+04:00)", "Izhevsk, Samara"),
                  new Tuple<string,string,string>("Mauritius Standard Time", "(UTC+04:00)", "Port Louis"),
                  new Tuple<string,string,string>("Saratov Standard Time", "(UTC+04:00)", "Saratov"),
                  new Tuple<string,string,string>("Georgian Standard Time", "(UTC+04:00)", "Tbilisi"),
                  new Tuple<string,string,string>("Volgograd Standard Time", "(UTC+04:00)", "Volgograd"),
                  new Tuple<string,string,string>("Caucasus Standard Time", "(UTC+04:00)", "Yerevan"),
                  new Tuple<string,string,string>("Afghanistan Standard Time", "(UTC+04:30)", "Kabul"),
                  new Tuple<string,string,string>("West Asia Standard Time", "(UTC+05:00)", "Ashgabat, Tashkent"),
                  new Tuple<string,string,string>("Ekaterinburg Standard Time", "(UTC+05:00)", "Ekaterinburg"),
                  new Tuple<string,string,string>("Pakistan Standard Time", "(UTC+05:00)", "Islamabad, Karachi"),
                  new Tuple<string,string,string>("India Standard Time", "(UTC+05:30)", "Chennai, Kolkata, Mumbai, New Delhi"),
                  new Tuple<string,string,string>("Sri Lanka Standard Time", "(UTC+05:30)", "Sri Jayawardenepura"),
                  new Tuple<string,string,string>("Nepal Standard Time", "(UTC+05:45)", "Kathmandu"),
                  new Tuple<string,string,string>("Central Asia Standard Time", "(UTC+06:00)", "Nur-Sultan"),
                  new Tuple<string,string,string>("Bangladesh Standard Time", "(UTC+06:00)", "Dhaka"),
                  new Tuple<string,string,string>("Omsk Standard Time", "(UTC+06:00)", "Omsk"),
                  new Tuple<string,string,string>("Myanmar Standard Time", "(UTC+06:30)", "Yangon (Rangoon)"),
                  new Tuple<string,string,string>("SE Asia Standard Time", "(UTC+07:00)", "Bangkok, Hanoi, Jakarta"),
                  new Tuple<string,string,string>("Altai Standard Time", "(UTC+07:00)", "Barnaul, Gorno-Altaysk"),
                  new Tuple<string,string,string>("W. Mongolia Standard Time", "(UTC+07:00)", "Hovd"),
                  new Tuple<string,string,string>("North Asia Standard Time", "(UTC+07:00)", "Krasnoyarsk"),
                  new Tuple<string,string,string>("N. Central Asia Standard Time", "(UTC+07:00)", "Novosibirsk"),
                  new Tuple<string,string,string>("Tomsk Standard Time", "(UTC+07:00)", "Tomsk"),
                  new Tuple<string,string,string>("China Standard Time", "(UTC+08:00)", "Beijing, Chongqing, Hong Kong, Urumqi"),
                  new Tuple<string,string,string>("North Asia East Standard Time", "(UTC+08:00)", "Irkutsk"),
                  new Tuple<string,string,string>("Singapore Standard Time", "(UTC+08:00)", "Kuala Lumpur, Singapore"),
                  new Tuple<string,string,string>("W. Australia Standard Time", "(UTC+08:00)", "Perth"),
                  new Tuple<string,string,string>("Taipei Standard Time", "(UTC+08:00)", "Taipei"),
                  new Tuple<string,string,string>("Ulaanbaatar Standard Time", "(UTC+08:00)", "Ulaanbaatar"),
                  new Tuple<string,string,string>("Aus Central W. Standard Time", "(UTC+08:45)", "Eucla"),
                  new Tuple<string,string,string>("Transbaikal Standard Time", "(UTC+09:00)", "Chita"),
                  new Tuple<string,string,string>("Tokyo Standard Time", "(UTC+09:00)", "Osaka, Sapporo, Tokyo"),
                  new Tuple<string,string,string>("North Korea Standard Time", "(UTC+09:00)", "Pyongyang"),
                  new Tuple<string,string,string>("Korea Standard Time", "(UTC+09:00)", "Seoul"),
                  new Tuple<string,string,string>("Yakutsk Standard Time", "(UTC+09:00)", "Yakutsk"),
                  new Tuple<string,string,string>("Cen. Australia Standard Time", "(UTC+09:30)", "Adelaide"),
                  new Tuple<string,string,string>("AUS Central Standard Time", "(UTC+09:30)", "Darwin"),
                  new Tuple<string,string,string>("E. Australia Standard Time", "(UTC+10:00)", "Brisbane"),
                  new Tuple<string,string,string>("AUS Eastern Standard Time", "(UTC+10:00)", "Canberra, Melbourne, Sydney"),
                  new Tuple<string,string,string>("West Pacific Standard Time", "(UTC+10:00)", "Guam, Port Moresby"),
                  new Tuple<string,string,string>("Tasmania Standard Time", "(UTC+10:00)", "Hobart"),
                  new Tuple<string,string,string>("Vladivostok Standard Time", "(UTC+10:00)", "Vladivostok"),
                  new Tuple<string,string,string>("Lord Howe Standard Time", "(UTC+10:30)", "Lord Howe Island"),
                  new Tuple<string,string,string>("Bougainville Standard Time", "(UTC+11:00)", "Bougainville Island"),
                  new Tuple<string,string,string>("Russia Time Zone 10", "(UTC+11:00)", "Chokurdakh"),
                  new Tuple<string,string,string>("Magadan Standard Time", "(UTC+11:00)", "Magadan"),
                  new Tuple<string,string,string>("Norfolk Standard Time", "(UTC+11:00)", "Norfolk Island"),
                  new Tuple<string,string,string>("Sakhalin Standard Time", "(UTC+11:00)", "Sakhalin"),
                  new Tuple<string,string,string>("Central Pacific Standard Time", "(UTC+11:00)", "Solomon Is., New Caledonia"),
                  new Tuple<string,string,string>("Russia Time Zone 11", "(UTC+12:00)", "Anadyr, Petropavlovsk-Kamchatsky"),
                  new Tuple<string,string,string>("New Zealand Standard Time", "(UTC+12:00)", "Auckland, Wellington"),
                  new Tuple<string,string,string>("UTC+12", "(UTC+12:00)", "Coordinated Universal Time+12"),
                  new Tuple<string,string,string>("Fiji Standard Time", "(UTC+12:00)", "Fiji"),
                  new Tuple<string,string,string>("Kamchatka Standard Time", "(UTC+12:00)", "Petropavlovsk-Kamchatsky - Old"),
                  new Tuple<string,string,string>("Chatham Islands Standard Time", "(UTC+12:45)", "Chatham Islands"),
                  new Tuple<string,string,string>("UTC+13", "(UTC+13:00)", "Coordinated Universal Time+13"),
                  new Tuple<string,string,string>("Tonga Standard Time", "(UTC+13:00)", "Nuku'alofa"),
                  new Tuple<string,string,string>("Samoa Standard Time", "(UTC+13:00)", "Samoa"),
                  new Tuple<string,string,string>("Line Islands Standard Time", "(UTC+14:00)", "Kiritimati Island")
          };
          return list;
      }
// appsetting.json

  "ScheduledReportTime": {
    "TimeZone": "AUS Eastern Standard Time",
    "daily-report-time": "01 08 * * *",
    "contamination-report-time": "05 08 * * *",
    "weekly-report-time": "15 08 * * 1",
    "monthly-report-time": "20 08 1 * *",
    "monthly-two": "00 11 1 * *",
    "weekly-report-two": "22 13 * * 1"
  },
  
  
//startup.cs
// timezone service
   services.AddScoped<ITimeZoneService, TimeZoneService>();
// send_locaTime_change_appsetting 


   // send localTimeZoneName & localTimeStr
    let localTimeZoneName = new Date().toLocaleDateString(undefined, { day: '2-digit', timeZoneName: 'long' }).substring(4);
    let localTimeStr = formatDate(new Date(), 'YYYY-MM-ddTHH:mm:ss', 'en-AU');
    formData.append("LocalTimezoneName", localTimeZoneName);
    formData.append("LocalTimeStr", localTimeStr);


	_repository.UpdateEmailSetting(newRecord);

	if (await _unitOfWork.SaveAsyc() > 0)
	{
	   // change appsetting.json value with offset hours
	   updateSetingValue(emailSetting.EmailName, emailSetting.SendTime.Hour, emailSetting.SendTime.Minute, emailSettingVM.LocalTimezoneName, emailSettingVM.LocalTimeStr);
       ...
     }



	private void updateSetingValue(string emailReportName, int hour, int minute, string localTimezoneName, string localTimeStr)
	{

		// get local timezone offset hours by local timezone name & time
		int offsetHours = this._timeZoneService.GetTimeZoneOffsetHoursByLocalTimezone(localTimezoneName, localTimeStr);

		_logger.LogInformation($"Get offset hours: " + offsetHours.ToString());
		string cronTime = this._timeZoneService.GetOffsetHourTimeCronStr(hour, minute, offsetHours);// report-time
		_logger.LogInformation($"Get cron time: " + cronTime);

		string sectionKey = sectionName + ':' + emailReportName.Replace('_', '-');
		_logger.LogInformation($"Update SectionKey: " + sectionKey);

		if (emailReportName.Contains("monthly"))
			this._timeZoneService.UpdateAppSetting(sectionKey, cronTime, "monthly");   // monthly = " 1 * *"
		else if (emailReportName.Contains("weekly"))
			this._timeZoneService.UpdateAppSetting(sectionKey, cronTime, "weekly");    // weekly =" * * 1"
		else if (emailReportName.Contains("daily") || emailReportName.Contains("contamination"))
			this._timeZoneService.UpdateAppSetting(sectionKey, cronTime, "daily");     // daily =  " * * *"
	}
// Some code
PreviousAuth get user info by emailNext.NET API Add Service

Last updated 11 months ago

Was this helpful?

🪤