How to set Max Date / Min Date to WinPhone DatePicker - windows-phone-8

I am developing WinPhone apps.
<DatePicker x:Name="MyDatePicker" MinYear="2016" MaxYear="2017"/>
The code is not working.
I am able to choose previous years and I am able to choose 2015, 2018, etc. If possible, I would like to disable the months and days in DatePicker itself.
In short, I would like to set minimum and maximum allowed date for calendar so that unwanted dates are disabled in the calendar.

According to documentation, XAML parser doesn't have a conversion logic for converting strings to dates as DateTimeOffset objects, so MinYear and MaxYear property couldn't be set as a XAML attribute string. There are to options to set these properties:
To do it in the C# code. An example could be found here.
To provide relevant properties in your view model class (or another object in the data context) and use bindings to propagate values to the DatePicker control.
View model class:
public DateTimeOffset MinYear
{
get { return new DateTime(2016, 1, 1); }
}
public DateTimeOffset MaxYear
{
get { return new DateTime(2017, 12, 31); }
}
XAML layout:
<DatePicker x:Name="MyDatePicker" MinYear="{Binding MinYear}" MaxYear="{Binding MaxYear}" />

If you are using Xamarin.Forms then
<StackLayout>
<DatePicker VerticalOptions="CenterAndExpand" Date="{x:Static sys:DateTime.Now}">
<DatePicker.Format>yyyy-MM-dd</DatePicker.Format>
<DatePicker.MinimumDate>
<sys:DateTime x:FactoryMethod="Parse">
<x:Arguments>
<x:String>Jan 1 2000</x:String>
</x:Arguments>
</sys:DateTime>
</DatePicker.MinimumDate>
<DatePicker.MaximumDate>
<sys:DateTime x:FactoryMethod="Parse">
<x:Arguments>
<x:String>Dec 31 2050</x:String>
</x:Arguments>
</sys:DateTime>
</DatePicker.MaximumDate>
</DatePicker>
Retrieved from https://developer.xamarin.com/api/type/Xamarin.Forms.DatePicker/
If you want to just have years, then use a normal picker and give it a list of years in your accepted range. https://developer.xamarin.com/api/type/Xamarin.Forms.Picker/

In Winphone 8.1 there is no way to set
minimum and maximum dates but as eugene-berdnikov suggested in the above post you can set MinYear and MaxYear for the month and day you'll have to handle through code validation.
But UWP(Universal Windows Platform) has a CalendarDatePicker using which you can set MinDate and MaxDate property
if you want to support windows 10 and future releases you may start migrating to UWP(Universal Windows Platform)
Here is a migration tutorial
Its as easy as Creating a New UWP project and copying existing files and rewrite some code thats all.
ViewModel Class
public DateTimeOffset MinDate
{
get { return new DateTime(2016, 1, 1); }
}
public DateTimeOffset MaxDate
{
get { return new DateTime(2017, 12, 31); }
}
XAML Layout
<CalendarDatePicker MinDate="{Binding MinDate}" MaxDate="{Binding MaxDate}"/>
Code behind
CalendarDatePicker calObj=new CalendarDatePicker();
DateTime minDate = new DateTime(2016, 1, 1, 0, 0, 0)
minDate = DateTime.SpecifyKind(minDate, DateTimeKind.Utc);
DateTimeOffset min_Date = minDate;
DateTime maxDate = new DateTime(2017, 1, 1, 0, 0, 0)
maxDate = DateTime.SpecifyKind(maxDate, DateTimeKind.Utc);
DateTimeOffset max_Date = maxDate;
calObj.MinDate=min_Date;
calObj.MaxDate=max_Date;
Kindly know that UWP also supports DatePicker which is part of windows phone 8.1
My suggestion is in winphone 8.1 use DatePicker and Windows 10 use CalendarDatePicker
Here is list of Date and Time controls available in UWP
Most of the windows phone 8.1 devices has got 10 update as well so you may see lots of people moving towards 10

Related

Expression.Error: A cyclic reference was encountered during evaluation. - using custom function NetWorkDays in Power Query

I have created a custom function from a blank query to calculate the number of days excluding holidays and the weekends, the function is below
Query1 = (StartDate as date, EndDate as date) as number =>
let
DateList = List.Dates(StartDate, Number.From(EndDate - StartDate) , #duration(1, 0, 0, 0)),
RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5),
RemoveHolidays = List.RemoveItems(RemoveWeekends, Holidays),
CountDays = List.Count(RemoveHolidays)
in
CountDays,
Custom1 = Query1
in
Custom1
Everything is working in the file on my computer, but the issue is when anyone else from my team is trying to use the file with queries there. We are getting error <Expression.Error: A cyclic reference was encountered during evaluation.>
I've tried to trace steps and find out when the error is occurring and it's always pointing at the custom function.
Please help me, I need to fix it asap so my team can use this.
Function screen
Calendar before function
Calendar after function
I was using this youtube guide to create function: https://www.youtube.com/watch?v=e2ic432NvhY
try changing your function to
(StartDate as date, EndDate as date) as number =>
let DateList = List.Dates(StartDate, Number.From(EndDate - StartDate) , #duration(1, 0, 0, 0)),
RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5),
RemoveHolidays = List.RemoveItems(RemoveWeekends, Holidays),
CountDays = List.Count(RemoveHolidays)
in CountDays
then, assuming Holidays is a query with some list of dates like
= {#date(2022,6,15),#date(2022,1,18)}
then
= Table.AddColumn(#"Changed Type", "Custom", each NetWorkDays([StartDate],[EndDate]))
works fine
Thanks everyone for such quick answers.
My issue was that first I've created custom function based on list of holidays and calendar and then i've used it in calendar as well. When I removed custom function from the calendar query, leaving only starting date of the week, ending date and week number it started to work again.

Spoof JSON (or other resource) while loading realtime Web site

I'm trying to write a userscript for a friend. The Website I'm writing it for (app.patientaccess.com) tells you what doctors appointments you have, (among other things). However, in order to write my userscript, I need to know how the app handle appointments for the following year.
At the moment, the only way to know is to wait until the end of the year when my friend starts making appointments for the following year. Since it's an Angular app, I'd rather, if possible, point it to a fabricated JSON file of my creation when the app requests that particular data. In that file I can give it some data for this year and next year and then I can see what happens with appointments made for the following year.
I'm hoping this can be done with an addon for Chrome or Firefox or perhaps some kind of free/open source software.
Thanks in advance.
I came up with a function that will accurately guess there year, given the day name, date and month, if it's within a couple of years either side of the current year.
function calculateYear(dayName, dayOfMonth, monthNum, returnDateObj) {
monthNum -= 1;
maxIterations = 3;
var startYear = (new Date()).getFullYear();
var dateObj = new Date(startYear, monthNum, dayOfMonth);
for (var i = 0; i < maxIterations; i++) {
dateObj.setYear(startYear + (1 * i));
if (dayName == daysOfTheWeek[dateObj.getDay()]) {
return (returnDateObj) ? dateObj : dateObj.getFullYear();
}
dateObj.setYear(startYear - (i + 1));
if (dayName == daysOfTheWeek[dateObj.getDay()]) {
return (returnDateObj) ? dateObj : dateObj.getFullYear();
}
}
return 'No Match';
}
It works a treat, as you can see here.

How to write a Quartz timer service that updates every 6 months?

I want a Quartz timer service for the update code below. Every six months, all users' keys should be updated according to their creationDate:
//dataTypes are date only
List<User> allDbUsers=userRepository.findAll();
Date currDate=new Date();
final long DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
for(User user:allDbUsers)
{
Date creationDate=user.getCreationDate();
String firstKey=user.getFirstKey();
Long diffInDays=(currDate.getTime()-creationDate.getTime())/DAY_IN_MILLIS;
if(diffInDays==180)
{
user.setSecondKey(firstKey);
user.setFirstKey("aH&#KK");
userRepository.saveAndFlush(user);
}
}
You can use Calendar for view diff between dates, for example:
Calendar currentDate = Calendar.getInstance();
Calendar sixMonthAfterCreation;
for (User user : allDbUsers) {
sixMonthAfterCreation = Calendar.getInstance()
sixMonthAfterCreation.setTime(user.getCreationDate());
sixMonthAfterCreation.add(Calendar.MONTH, 6);
String firstKey = user.getFirstKey();
if (currentDate.after(sixMonthAfterCreation)) {
user.setSecondKey(firstKey);
user.setFirstKey("aH&#KK");
userRepository.saveAndFlush(user);
}
}
or if you use java 8 you can convert you creation date to LocalDate and view diff.
If I right understand you, you want use Quartz Scheduler. I did not use it but I think you need implement org.quartz.Job, override execute method and write code for updating users in it.
For more information about Quartz Scheduler look this question
One clarification this code not for run scheduler, it code for method job.excecute(what job must do). Scheduler should run every midnight(for example), then every midnight will be called execute method which find all user for update and do it.

Converting Phonegap app datetime fields to work on ios7

So I just found out that the datetime input fields I use all over my app are no longer working on IOS7, so I found that the datetime-local input type is still supported. Timezone is not important to the function of my app, so this is ok. The problem is, the code I was using to populate and retrieve the date values from the input fields does not work. Here is my code:
$("#date").val(pv.When);
To set it, where date is the id of my input and pv.When is a datetime object
theVisit.When = new Date($("#date").val());
To retrieve it, right now neither do anything, the field is empty when i load the form, and the value does not save. Do I need to do anything special to make this work?
OK, what I did was this, I wrote 2 utility functions, one to set the value of the datetime-local field and one to get the value out as a date. You will notice as part of the fix I am using the Moment.js date helper library.
Here are my 2 functions:
function getDateTimeForPicker(d) {
var offset = d.getTimezoneOffset() / 60;
d.setMinutes(d.getMinutes() - d.getTimezoneOffset())
return d.toISOString().replace("Z", "");
}
function getDateTimeFromPicker(d) {
var m = moment(d);
var ret = m.toDate();
return ret;
}
so I can set as easy as :
$("#dateTimeBox").val(getDateTimeForPicker(new Date()));
This is tested and working fine on iOS7

Start or End of week in Actionscript

I am looking for a way of getting the start of the week relative to today in Actionscript using (and currently stuck with) Flex 4.1. In Java I would do this using the Calendar class via:-
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.DAY_OF_WEEK,
1);
return cal.getTime();
I can't seem to find any solution that is anywhere as elegant - am I missing something?
There are two classes, of the same name, DateTimeFormatter. One is a pure Actionscript class, the other is a new class added to Flex 4.5 that wraps the Actionscript version. The Flex version does some of the heavy lifting for you.
There is a getFirstWeekday() method, it will be respective of the locale you specify.
[Edit]
I got carried away, didn't answer your question specifically. I'm not aware of anything more elegant than the DateTimeFormatter. But from there you can use a Date object to get the current time, and get what you're after.
There are a handful of date utilities, but I'm not aware of this particular solution. Are you looking for something like this:
var timeFormatter:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.NONE, DateTimeStyle.SHORT);
var firstDay:int = timeFormatter.getFirstWeekday()
var now:Date = new Date();
var dayDelta:int = now.day - firstDay;
var firstDayInMillis:Number = now.time - (dayDelta * 86400 * 1000);
// you can construct a new Date from here: var first:Date = new Date(firstDayInMillis);