I am trying to convert HijriCalendar to Gregorian Calendar in Xamarin Forms app. However, it seems that Xamarin Android is not happy with it. I haven't test it in Xamarin iOS.
I am using code from Cannot convert from Hijri Date to Gregorian date (c#)
and I am getting below exception when instantiating the HijriCalendar object in line
DTFormat.Calendar = new System.Globalization.HijriCalendar(); //exception is thrown
{System.ArgumentOutOfRangeException: Not a valid calendar for the
given culture. Parameter name: value at
System.Globalization.DateTimeFormatInfo.set_Calendar
(System.Globalization.Calendar value) [0x00142]
I have checked Converting Dates between Calendars in Xamarin.Android solution, but that suggests another library which I am not interested to use.
I have changed the Linking properties in Android Project to None, Sdk Assemblyies Only, and Sdk & User Assembly but didn't worked. So, how to convert Gregorian Date to HijriDate in Xamarin forms?
I also added the following codes in OnCreate method in Xamarin Android from Thai crash: Not a valid calendar for the given culture
_ = new System.Globalization.GregorianCalendar();
_ = new System.Globalization.HijriCalendar();
_ = new System.Globalization.PersianCalendar();
_ = new System.Globalization.UmAlQuraCalendar();
_ = new System.Globalization.ThaiBuddhistCalendar();
Try to use System.DateTime:
Calendar hijiri = new HijriCalendar();
DateTime date = new DateTime(1442, 4, 15, hijiri);
Console.WriteLine(date.Year); // 2020
Console.WriteLine(date.Month);//11
Console.WriteLine(date.Day); // 30
Calendar gregorian = new GregorianCalendar();
DateTime d = new DateTime(2020, 11, 30, gregorian);
var year = hijiri.GetYear(d); //1442
var month = hijiri.GetMonth(d); //4
var day = hijiri.GetDayOfMonth(d); //15
and another way is using NodaTime.
I found simular problem on this link
https://github.com/xamarin/Xamarin.Forms/issues/4037
// These classes won't be linked away because of the code,
// but we also won't have to construct unnecessarily either,
// hence the if statement with (hopefully) impossible
// runtime condition.
//
// This is to resolve crash at CultureInfo.CurrentCulture
// when language is set to Thai. See
// https://github.com/xamarin/Xamarin.Forms/issues/4037
if (Environment.CurrentDirectory == "_never_POSSIBLE_")
{
new System.Globalization.ChineseLunisolarCalendar();
new System.Globalization.HebrewCalendar();
new System.Globalization.HijriCalendar();
new System.Globalization.JapaneseCalendar();
new System.Globalization.JapaneseLunisolarCalendar();
new System.Globalization.KoreanCalendar();
new System.Globalization.KoreanLunisolarCalendar();
new System.Globalization.PersianCalendar();
new System.Globalization.TaiwanCalendar();
new System.Globalization.TaiwanLunisolarCalendar();
new System.Globalization.ThaiBuddhistCalendar();
new System.Globalization.UmAlQuraCalendar();
}
Good luck!
Related
I'm trying to follow the Microsoft Docs on getting started with Razor. When I try to implement the following code I get the errors detailed in the comments:
Solution/Project/Pages/AddNumbers.cshtml :
#{
var total = 0;
var totalMessage = "";
if(IsPost) { // The name 'isPost' does not exist in the current context
// Retrieve the numbers that the user entered.
var num1 = Request["text1"]; // CS0103 The name 'Request' does not exist in the current context
var num2 = Request["text2"]; // CS0103 The name 'Request' does not exist in the current context
// Convert the entered strings into integers numbers and add.
total = num1.AsInt() + num2.AsInt();
totalMessage = "Total = " + total;
}
}
I think I've followed the instructions faithfully, but can't think where I've made an error. What's the fix?
IsPost does not exist if you do not create it. You can create such a property, defaulting to false and setting it to true in your OnPost handler.
Similarly, you cannot refer to Request like you tried in your code, you need a property for that too.
Since num1 and num2 were not successfully initialized, they cannot be successfully converted to int either.
I think the problem is that the documentation I was following is for "ASP.NET Web Pages (Razor) 3", but I was trying to run the code on "ASP.NET Core Web App".
As Lajos Arpad pointed out, I would need to create my own isPost property .
I have put SharePoint Date Time control in asp.net application page...Problem is by default it is taking Today date how to "stop tanking today date"...Thank you
I prefer using own control instead of sp date control.
var dateControl = new DateTimeControl();
dateControl.ID = "anyId";
dateControl.DateOnly = true;
dateControl.CssClassTextBox = "cssclass";
dateControl.LocaleId = Convert.ToInt32(SPContext.Current.RegionalSettings.LocaleId);
dateControl.OnValueChangeClientScript = "onApplyDateChangeValue(event)";
//if you want to set any value
dateControl.SelectedDate = DateTime.ParseExact("dateString", "dd.MM.yyyy",CultureInfo.InvariantCulture);
//Add to app page
"elementID".Controls.Add(dateControl);
It is working fine
write below code in side click function:
if (!spCal2.IsDateEmpty)
{
lblShowdtae.Text = dtSPdate.SelectedDate.ToString();
}
I'm new to Twitter API & trying to get tweets with a specific hashtag in my C# Web application.
I was able to authenticate my app & get JSON from Twitter ,here are some questions/issues I have:
API can only return maximum 100 tweets in one call,so how I can check if I've more tweets?
If somebody have code example to convert that(Twitter's) JSON into custom class object,so
I can count tweets (I tried but getting errors)?
I used this to generate c# classes from json & getting error while doing following:
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
RootObject routes_list = (RootObject)json_serializer.DeserializeObject(s);
Tweetinvi manages that for you. Here is an example returning 200 results.
var searchParameter = Search.GenerateSearchTweetParameter("#my_tag");
searchParameter.Lang = Language.English;
searchParameter.SearchType = SearchResultType.Popular;
searchParameter.MaximumNumberOfResults = 200;
searchParameter.Since = new DateTime(2013, 12, 1);
// ... There are many different parameters that can be set
var tweets = Search.SearchTweets(searchParameter);
tweets.ForEach(t => Console.WriteLine(t.Text));
// Get number of objects
var nbTweets = tweets.Count();
Hope this helps.
Certainly Tweetinvi as user64 said, is a great API, please for version 2.1 the following does the job. Be aware of set RateLimitTrack mode
// Set up my credentials in (https://apps.twitter.com)
Auth.SetUserCredentials(consumer_key, consumer_secret, access_token, access_token_secret);
// Enable Automatic RateLimit handling
RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackAndAwait;
var searchParameter = Search.CreateTweetSearchParameter("#My_Tag");
searchParameter.Lang = LanguageFilter.Spanish; // or English
searchParameter.SearchType = SearchResultType.Recent;
searchParameter.MaximumNumberOfResults = 200; // or any number
searchParameter.Since = new DateTime(2013, 12, 1);
var tweets = Search.SearchTweets(searchParameter); // tweets.Count() has the actual searched tweets
foreach(var item in tweets)
{
// do anything with item and its properties example: item.Text;
}
Yesterday, I wrote this code :
EventsResource.ListRequest req = service.Events.List("primary");
req.TimeMin = DateTime.Now.AddMonths(-2).ToString("o");
req.ShowDeleted = true;
req.UpdatedMin = LastSync.ToString("o");
req.SingleEvents = true;
req.MaxResults = 5;
TimeMin and UpdateMin were strings (string? datatype).
This morning, the code breaks.
So I updated the NuGet packages.
Now, those two fields (and any date field in the API) are typed "DateTime?"
So I updated my code to :
EventsResource.ListRequest req = service.Events.List("primary");
req.TimeMin = DateTime.Now.AddMonths(-2);
req.ShowDeleted = true;
req.UpdatedMin = LastSync;
req.SingleEvents = true;
req.MaxResults = 5;
I also tried to use "new DateTime?(DateTime.Now.AddMonths(-2))"
Now I get a "Bad Request" error as soon as TimeMin or UpdateMin is filled.
If I comment thoses lines, I get events from my calendar.
What's wrong ? Bug in the new API release ?
Try the new NuGet package - https://www.nuget.org/packages/Google.Apis.Calendar.v3/ It should be fixed on the new version.
We are going to announce very soon the release of 1.7.0-beta (so keep updated on http://google-api-dotnet-client.blogspot.com/)
I have the following code for use in my asp.net website:
CalendarService service = new CalendarService("mycalendar");
EventQuery query = new EventQuery();
query.Uri = new Uri(group.GroupEventsURL);
query.SingleEvents = true;
query.SortOrder = CalendarSortOrder.ascending;
query.ExtraParameters = "orderby=starttime";
query.NumberToRetrieve = 50;
query.TimeZone = "America/Chicago";
EventFeed feed = service.Query(query);
Which produces the following URL:
http://www.google.com/calendar/feeds/TRIMMEDgroup.calendar.google.com/private-TRIMMED/full?max-results=50&orderby=starttime&ctz=America%2FChicago&sortorder=ascending&singleevents=true
According to the documentation (emphasis mine), I expect the Times in each EventEntry to be in the Central time zone:
ctz: The current timezone. If not specified, times are returned in the calendar time zone.
Times in the resulting feed will be represented in this timezone.
Replace all spaces with underscores (e.g. "ctz=America/Los_Angeles").
But my server is hosted in Arizona, so (for now) all of the dates on the calendar are two hours earlier than they should be. Am I doing something wrong? How do I get the dates in the feed to be in the Central time zone even though the server is in Arizona?
I do not plan on moving my hosting any time soon, but since Arizona does not participate in Daylight Savings Time, I cannot simply add two hours to every date.
Don't fight it. The Google.GData.Calendar library sets each time to the system's local time. Here's what I could dig up about it.
You'll need to convert all those times from every EventEntry
DateTime offsetStartTime = GetTimeZoneOffset(entry.Times[0].StartTime, "Mountain Standard Time");
public static DateTime GetTimeZoneOffset(DateTime dt, string win32Id)
{
var timeUtc = dt.ToUniversalTime();
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById(win32Id);
DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);
return cstTime;
}
I am still open to other ideas, but here is what I got to work. I created my own CalendarService class, which converts the dates from:
2010-10-13T18:30:00.000-05:00
to:
2010-10-13 18:30:00
These dates are then converted to the same (and correct) DateTime in any time zone.
internal class CalendarService2 : CalendarService
{
public CalendarService2(string applicationName) : base(applicationName) { }
public new EventFeed Query(EventQuery feedQuery)
{
EventFeed feed = new EventFeed(feedQuery.Uri, this);
using (Stream input = base.Query(feedQuery.Uri, DateTime.MinValue))
{
XmlDocument doc = new XmlDocument();
doc.Load(input);
XmlNodeList nodes = doc.SelectNodes("(//#startTime|//#endTime)[contains(.,'.000-')]");
foreach (XmlNode node in nodes)
{
node.Value = node.Value.Remove(node.Value.Length - 10).Replace('T', ' ');
}
using (MemoryStream output = new MemoryStream())
{
doc.Save(output);
output.Position = 0;
feed.NewAtomEntry += new FeedParserEventHandler(this.OnParsedNewEntry);
feed.NewExtensionElement += new ExtensionElementEventHandler(this.OnNewExtensionElement);
feed.Parse(output, AlternativeFormat.Atom);
}
}
return feed;
}
}