Apple calendar integration in iOS app? - objective-c

Does anyone integrate iCalendar your application ?
I have to implement calendar with event handling .
Just same as ---> https://github.com/jumartin/Calendar
I have tried with many application available on github but cannot finf single application for calendar event handling Just like our Apple Calendar.
Thanks in advance.

Customise start date and end date based on you're requirements this code will add events to you're iPhone calendar
let dateFormatter2: NSDateFormatter = NSDateFormatter()
dateFormatter2.dateFormat = "MM/dd/yyyy hh:mma"
let date: NSDate = dateFormatter2.dateFromString(startDate)!
let date2: NSDate = dateFormatter2.dateFromString(EndDate)!
if (EKEventStore.authorizationStatusForEntityType(.Event) != EKAuthorizationStatus.Authorized) {
eventStore.requestAccessToEntityType(.Event, completion: {
granted, error in
self.createEvent(eventStore, title: self.HelpEventString, startDate: date , endDate: date2)
})
} else {
createEvent(eventStore, title: "Event created on particular date between start and time interval and end date time interval", startDate: date, endDate: date2)
}
func createEvent(eventStore: EKEventStore, title: String, startDate: NSDate, endDate: NSDate) {
let event = EKEvent(eventStore: eventStore)
event.title = title
event.startDate = startDate
event.endDate = endDate
event.calendar = eventStore.defaultCalendarForNewEvents
do {
try eventStore.saveEvent(event, span: .ThisEvent)
savedEventId = event.eventIdentifier
} catch {
}
}

Related

Youtrack Workflow to set issue due date based on issue start date + estimate

I am trying to set up a workflow on youtrack where it sets automatically the end date based on the start date + estimates.
For example, my issue start date is 2022/10/01 and it has an estimate of 10d (10 days, for example). I want that the end date to be set of 2022/10/10.
I couldn't figure out how to set this rule as I couldn't user the workflow constructor for it.
Thanks
Here is an example of a similar workflow that automatically adds the Planned time value to Start date field and writes the result in the Due date field:
const entities = require('#jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
title: 'End date',
guard: (ctx) => {
return (ctx.issue.fields.isChanged(ctx.Plan) || ctx.issue.fields.isChanged(ctx.StartDate)) && ctx.issue.fields.Plan != null && ctx.issue.fields.StartDate != null;
},
action: (ctx) => {
const issue = ctx.issue;
var periodestimate = issue.fields.Plan;
var minutesestimate = !periodestimate ? 0 : (periodestimate.getMinutes() + 60 * (periodestimate.getHours() + 24 * (periodestimate.getDays() + 7 * periodestimate.getWeeks())));
ctx.issue.fields.EndDate = issue.fields.StartDate + (minutesestimate * 60000);
},
requirements: {
Plan: {
name: "Planned time",
type: entities.Field.periodType
},
EndDate: {
name: "Due Date",
type: entities.Field.dateType
},
StartDate: {
name: "Start Date",
type: entities.Field.dateType
}
}
});

How to change xAxisTickFormatting in ngx-charts-line-chart based on timeline selection?

By default, ticks are formatted based on time range selection in timeline. If it pans across days it shows month and if it is with in a day, it shows only time. This is great!
Now I want to localize these ticks. I could provide xAxisTickFormatting to get this done but I want to have the formatting based on the time range selection. "MMM DD" or "HH:MM" based on the current time range selection.
For this I need to change the formatting function dynamically on time range selection event. Is there such an event? Or is there any other way to achieve this?
In your chart, among the other attributes, you can declare
<ngx-charts-bar-horizontal-normalized
...
[xAxis]="true"
[xAxisTickFormatting]='formatPercent'
...
</ngx-charts-bar-horizontal-normalized>
formatPercent is a function declared in your .ts file (I'm using Angular) written like
formatPercent(val) {
if (val <= 100) {
return val + '%';
}
}
For any reference check the documentation here
Hope this helps.
It looks like, date is formatted based on the d3 logic. It uses the precision available to that tick. So if date is 12/15/2020 11:30:00, precision is at minute level. Similarly if date is 12/15/2020 00:00:00, precision is at day level.
Now we can choose the format options accordingly.
var locale = 'fr-FR'; // 'en-US'
function formatDate(value) {
let formatOptions;
if (value.getSeconds() !== 0) {
formatOptions = { second: '2-digit' };
} else if (value.getMinutes() !== 0) {
formatOptions = { hour: '2-digit', minute: '2-digit' };
} else if (value.getHours() !== 0) {
formatOptions = { hour: '2-digit' };
} else if (value.getDate() !== 1) {
formatOptions = value.getDay() === 0 ? { month: 'short', day: '2-digit' } : { weekday: 'short', day: '2-digit' };
} else if (value.getMonth() !== 0) {
formatOptions = { month: 'long' };
} else {
formatOptions = { year: 'numeric' };
}
return new Intl.DateTimeFormat(locale, formatOptions).format(value);
}
var dates = ['12/15/2020 11:30:30', '12/15/2020 11:30:00', '12/15/2020 11:00:00', '12/15/2020 00:00:00', '12/13/2020 00:00:00', '12/01/2020 00:00:00', '01/01/2020 00:00:00'];
for (date of dates) {
console.log(date, '=>', formatDate(new Date(date)));
}
Now this function can be used as
<ngx-charts-line-chart
[xAxis]="true"
[xAxisTickFormatting]="formatDate">
</ngx-charts-line-chart>

Schedule local notification swift4

I've made a local notification with swift4 every day every at 17.00. and I want the notification to not show up on holidays (Saturday, Sunday). How can I do that?
Here is my code:
// schedule notification every day
var dateComponents = DateComponents ()
dateComponents.hour = 17
dateComponents.minute = 00
dateComponents.day = 7
let trigger = UNCalendarNotificationTrigger (dateMatching: dateComponents, repeats: true)
let request = UNNotificationRequest.init (identifier: "Everyday", content: content, trigger: trigger)
func createDate(weekday: Int, hour: Int, minute: Int, year: Int)->Date{
var components = DateComponents()
components.hour = hour
components.minute = minute
components.year = year
components.weekday = weekday // sunday = 1 ... saturday = 7
components.weekdayOrdinal = 10
components.timeZone = .current
let calendar = Calendar(identifier: .gregorian)
return calendar.date(from: components)!
}
//Schedule Notification with weekly bases.
func scheduleNotification(at date: Date, body: String, titles:String) {
let triggerWeekly = Calendar.current.dateComponents([.weekday,.hour,.minute,.second,], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
let content = UNMutableNotificationContent()
content.title = titles
content.body = body
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "todoList"
let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
//UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print(" We had an error: \(error)")
}
}
}
Swift 4
📢///CreateDateForNotification
func createDate(day: Int, month : Int, hour: Int, minute: Int, year: Int)->Date{
var components = DateComponents()
components.hour = hour
components.minute = minute
components.year = year
components.day = day
components.month = month
components.timeZone = .current
let calendar = Calendar(identifier: .gregorian)
return calendar.date(from: components)!
}
📢///CreateNitification
func scheduleNotification(at date: Date, identifierUnic : String, body: String, titles:String) {
let triggerWeekly = Calendar.current.dateComponents([.day, .month, .hour,.minute, .year], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
let content = UNMutableNotificationContent()
content.title = titles
content.body = body
content.sound = UNNotificationSound.default
content.categoryIdentifier = "todoList2"
let request = UNNotificationRequest(identifier: identifierUnic, content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
/// UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: ["textNotification2"])
/// UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print(" We had an error: \(error)")
}}
}
📢///Use
scheduleNotification(at: createDate(day : 11, month : 2, hour: 15, minute: 5, year: 2018), identifierUnic: "unic1", body: "Notification day", titles: "Notification titles1")

</my-date-picker> using ngmodel how should i convert date format and send

I am getting date like this 2018-10-17T00:00:00.000Z i should convert to 17.10.18 and send through [(ngModel)] by using my date picker
Can you help me.
got solution.
var availYear = moment(availDate).format("YYYY");
var availMonth = moment(availDate).format("M");
var availDay = moment(availDate).format("DD");
this.model = { date: { year: availYear, month: availMonth, day: availDay } };

TypeError: expected dynamic type 'double' but had type 'string'

I'm running into this error when trying to use datePickerAndroid and setting the state afterwards.
Error Message
I feel like the problem may be from the initial state being a new Date() but not 100% sure.
_isAndroid = async () => {
let {action, year, month, day} = await DatePickerAndroid.open({
date: this.props.startDate,
});
if (action === DatePickerAndroid.dismissedAction) {
this.props.closeModal()
} else {
const date = year + "-" + month + "-" + day
this.props.onDateChange(date)
}
}
Prop Function:
onDateChange = (newDate) => {
this.setState({currentDate: newDate}) // <- This one is breaking
let dates = this.state.dates;
let index = this.state.currentIndex;
if (this.state.currentKey === "start") {
dates[index].start = newDate
} else {
dates[index].end = newDate
}
this.setState({dates: dates});
}
I've narrowed it down to the first setState, and I've tried making the initial state a string as well as setting the state to a simple string but still getting the error.
For DatePickerAndroid
expected dynamic type double
In other words native component wants time, but you put string. You this.props.startDate is string, transfer time in time format. Example:
const {action, year, month, day} = await DatePickerAndroid.open({
date: new Date() // <- This is Date, not string!
});
Good luck!