App Overview
I'm building an iOS app in Swift that shows a list of events. The data that I have for the events shows the name of the event, the start date (day, month, year), and the end date (day, month, year).
When the data is pulled from Firebase, I look at the start and end months and show the event for the appropriate month in a table view. The data is shown by month, so a user looking at May only sees May events and has to choose a different month to see events from that month.
Problem
Some events stretch for several months. For example, if an event begins in July and ends in September, my current implementation won't show the events during August.
Possible Solutions
I'm looking for an elegant way to programmatically check for this case and make sure it's shown in the correct month rather than manually manipulating the data to state the months in between.
If you have any suggestions, please let me know. Here is the solution that I'm considering:
Add a Bool data point saying if the event stretches several months or not. When events for a specific month are shown, check through all of these events to see if the month selected is greater than the start month of the event and less than the end month of the event.
This breaks down if the event stretches from one year into the next. I would need to add additional logic to handle that.
It sounds like you are simply comparing the displayed month to the event's start month and the event's end month.
Without any specifics your basic logic to determine whether to show an event in a displayed month is to see if the displayed month is greater to or equal to the event start month and less than or equal to the even end month.
In pseudo code that would essentially be:
if displayMonth >= event.startMonth && displayMonth <= event.endMonth {
// show event
}
Of course this needs to account for the year as well.
In addition to check month you also need to check year. For example:
// Check start date
if (displayYear == event.startYear && displayMonth >= event.startMonth) || displayYear > event.startYear {
// Check end date
if (displayYear == event.endYear && displayMonth <= event.endMonth) || displayYear < event.endYear {
// show event
}
}
Let me know if you need more information or description of this code
comparing dates will work for you.
compare current date with starting date and ending date.
current date should be greater than starting date and less than ending date.
Here is code snippests for Date comparision
if currentDate.compare(startingDate) == .OrderedAscending && currentDate.compare(endingDate) == . OrderedDescending {
//Here will your event code will come.
}
Related
I am developing an automated calendar for a school on AirTable, but I am struggling to add if there is a bank holiday between the start date and end date. If the bank holiday falls on a weekday, it needs to add +1 day to the end date.
I have created a "bank holiday" table, as well as a full calendar table (containing everyday of the year and what weekday it falls on).
I'd like for the user to have the end date generated automatically by only writing the start date.
For example:
I have a session starting on Monday, 7th of march. The "session type" would be "Course 1", which has a duration of 10 days (two weeks, monday to friday - I don't know if the duration should be 14 days instead?). If there's a bank holiday in the 10 days after the start date, and it's on a weekday, it needs to add +1 to the end date. If the end date falls on a sunday, it needs to add +2 so that it ends on a Monday.
The course is divided in multiple classes, it would also be awesome to have a timeline view with the full Course and all the classes.
Here are some screenshots of my tables :
I know there is a possibility to write a script in Python with an AirTable API... but is there an easier way ?
I've dealt with a problem like this before: when an event happened in relation to other events mattered.
You'd think by the use of the words "in relation" that you could deal with this in a relational way, but I see it as a rule:
If Event A happens at Time 1, and it's so much or so little time from Event B, then do with Event A...
And, again by my way of thinking, rules are expressed in code.
And if you actually even can express that with a relation, I think it'd be very convoluted.
So, for your problem, you need to encode every schedule-able day that's 10 working days or less before a Bank Holiday (BH) so that if the day is selected you know it's less than 10 days from a BH and can conditionally add another day to the end date.
I looked at your examples, and here's my solution. I have a Calendar table which has all days, and two supporting "Bank Holiday" fields: does the date fall on a BH, and if not, is the date 10 days or less from a BH. We're looking at my All view, here:
I also have the view, Weekday, not bank holiday, and that's the view that you can pick a day from to schedule an event from the Event table.
The Event table:
You pick a day from the Start day field. Start day < 10 work days to Bank holiday? is a lookup field from the Calendar table for that day. End day is this formula:
DATETIME_FORMAT(
DATEADD(
{Start date},
IF(
{Start day < 10 work days to Bank holiday?},
14,
13),
'day'),
'ddd, MMM Do')
I am trying to create a custom function on a form to define a week Number.
I have created a table that defines the week number.
Example WeekNo, StartDay, End Day
example: WeekNo 1 StartDay = 3/29/2020, End Day 4/4/2020
I have a Date box on my form if I enter a date of 3/29/2020
I would like 1 to be populated in my week number box.
On my form in the row source I have designed a Dlookup query
=DLookup("[WeekNumber]", "tblWeekNumber", "[Startdate] >= " & frmSearchNew.dt_Date & "") & [EndDate] <= frmSearchNew.dtDate
When I change to from view I get the error the record source specified on this form does not exist.
The table tblWeekNumber has the fields ID, WeekNo, StartDay and EndDay.
Where am I going wrong? any help is appreciated.
There are quite a few issues with the DLookup that you have put together.
Firstly, the field that you are looking for and the fields that you are using as criteria do not appear to match those in the table - WeekNumber/WeekNo, StartDate/StartDay, EndDate/EndDay;
Next, the logic for the lookup is wrong. You are trying to find a the week number that has a start date that is greater than the entered date, and an end date that is less than the entered date. What you should be looking for is a start date before the entered date, and an end date after the entered date.
Finally, dates are a bit funny in Access. You need to wrap them in '#' so that Access knows they are dates, and you should also take care to disambiguate them - 03/04/2020 could be either 3rd April or 4th March depending on you nationality.
Putting it all together, the final control source should look like:
=DLookUp("WeekNo","tblWeekNumber","StartDay<=#" & Format([dt_Date],"dd-mmm-yyyy") & "# AND EndDay>=#" & Format([dt_Date],"dd-mmm-yy") & "#")
Regards,
We're using the following rule to mark work items that delay 2 days or more:
Changed Date <= #Today - 2
Work Item Type = Task
State = In Progress
(Then, color the task in red)
The problem is that when a task gets started on Friday, on Monday it will be red, even though only one working day has passed.
Is there a way around this?
This is not available to do this. For Changed Date field:
Change Date
The date and time when a work item was modified.
Reference name=System.ChangedDate, Data type=DateTime.
Since using data time type, it's not able to auto exclude weekends, this is by designed for now.
State Change DateThe date and time when the value of the State field changed.
DateTime
= , <> , > , < , >= , <= , =[Field], <>[Field], >[Field], <[Field], >=[Field], <=[Field], In, Not In, Was Ever Macros: #StartOfDay, #StartOfWeek, #StartOfMonth, #StartOfYear, and #Today; each of these
macros can be specified with a +/- n interger.
There has also been a related feature request:
Add option to exclude weekends when setting up Styling rules using the 'Changed Date' field rule criteria
https://developercommunity.visualstudio.com/idea/376310/add-option-to-exclude-weekends-when-setting-up-a-s.html
You could vote up it and our PM will kindly review it. Unfortunately, we do not have any perfect solution/workaround, you may have to manually change/update the colored task based on those tasks which get started on Friday.
I'm trying to create a simple counter/habit tracking app that allows users to see how many times they've completed a task over a certain amount of time (daily/weekly/monthly/yearly/total).
My question is: what is the best way to track variables over time such that when the user selects a time period, the variable's value can update to reflect that change?
A few examples to clarify what I mean:
A user who initially created a monthly timer to track workouts should be able to switch to a weekly timer and see the data update as needed (there should be fewer in a week than in a month).
A user who has created a daily counter should see the daily counter reset to 0 at midnight each day, with the previous day's value visible to compare.
A user who has created a "total" counter should be able to switch to any time period (daily/weekly/monthly/yearly) and see the counter update as needed.
The UI for my app is basically a custom tableview with the counter number, counter name, and the time period over which the counter number is being tracked. A detail view allows users to add to/subtract from the counter's value.
I have been wracking my brain and Google for a long time, so I'd really appreciate any help!
Each task should have a date. When app needs to query for the average per day/week/month/year you can use a NSPredicate to restrict only the results from a given time period.
For instance, here's a predicate that models the last-week scenario that I have written for an app of mine:
func lastWeekPredicate() -> NSPredicate {
let calendar = NSCalendar.currentCalendar()
let endDate = NSDate()
let startDate = calendar.dateByAddingUnit(.CalendarUnitDay, value: -7, toDate: endDate, options: nil)
return NSPredicate(format: "day >= %# AND day =< %#", argumentArray: [startDate!, endDate!])
}
Let's say you modelled your data with Core Data. Querying with this predicate would give you the results of all the tasks that were completed in the last week. The predicate can be modified to work for days, months, year, or any specified number of days.
Is this possible to evaluate the duration between a specified date on a form of a workflow, and the system date ? that what I want to do, in order to show (if this possible too) a short message if 1 day occurs since the specified date above, forbidding the transition of the status Closed to Reopened...
Thanks a lot,
Christophe
I think the Script Runner has a validator that does something like this but I can't find it. Then you could write a post function with the Script Runner. Otherwise it's back to creating a custom validator, as described in my book Practical JIRA Plugins (O'Reilly)
You can use the ScriptRunner plugin in addition with the following script in the validator section for the Reopened transition:
Date now = new Date()
Date cfDate = new Date(cfValues['YourCustomField'].getTime())
new Date(now.getYear(), now.getMonth(), now.getDate()).compareTo(cfDate) <= 0
Replace YourCustomField with the name of your custom field. This will ensure that the transition will check whether the current date is beyond the date set in the custom field, and blocks it if it is.
First of all, thank you for your answer.
It works to allow transition when dates are similar, but my purpose was modified by my responsible. He would like to allow the transition if dates are similar or if the duration between them is only 1 day or less.
Example :
System date is 09/07/2013 (Paris)
My date (dd/mm/yyyy format) Transition allowed Why
07/07/2013 NO my date is former to system date
08/07/2013 NO my date is former to system date
09/07/2013 YES my date and system date equals
10/07/2013 YES only 1 day occur between 2 dates
11/07/2013 NO 2 days occur between 2 dates
Here is the code I wrote in order to do that, but it does'nt work (maybe a Java syntax error?) :
Date now = new Date()
Date cfDate = new Date(cfValues['Date de clôture réelle de la demande'].getTime())
new Boolean(((now.getTime() - cfDate) / 86400000) <= 1) && (now.getTime() >= cfDate ))
Excuse me for my english. I'm french, and I try to improve my English.
Thanks a lot.