Date() Runtime error and crash

  1. 3 years ago

    Joel_Eisenstat

    4 May 2018 User since 2016

    Good morning ,
    This causes an error and crash
    date = Date(date,86400);
    todaylabel(date);
    where date = Date() ; // todays date
    Runtime Error
    An error occurred while reading key year ([<CREOApplication 0x61300004fc00> valueForUndefinedKey:]: this class is not key value coding-compliant for the key year.)
    Trying to advance the day by 1 day
    Regards
    Joel

  2. marco

    4 May 2018 Administrator User since 2016

    Hi @Joel_Eisenstat do you have a sample project?
    I don't understand what todaylabel is and I am not able to reproduce the crash.

  3. Joel_Eisenstat

    4 May 2018 User since 2016

    next arrow on window 2

  4. Joel_Eisenstat

    4 May 2018 User since 2016

    var time = Date(datetime); // datetime = 2018-05-02 00:00:26+00
    var hour = time.hour ; // ----> this causes an error
    Runtime Error
    An error occurred while reading key hour ([<CREOApplication 0x613000011840> valueForUndefinedKey:]: this class is not key value coding-compliant for the key hour.).

  5. marco

    5 May 2018 Administrator User since 2016

    Hi @Joel_Eisenstat I was able to identify the issue and fix an issue.
    Basically you are using the Date init in a wrong way.

    Date with one parameter expects it to be a number as reported from the documentation:
    http://docs.creolabs.com/classes/Date.html
    For example: var d = Date(120);

    A correct error message will be reported in the upcoming new release.
    Thanks!

  6. Joel_Eisenstat

    5 May 2018 User since 2016

    Ok , and that number is seconds in so far as the Date function is concerned ie time interval - day = 86400 ? Always convert to seconds for date manipulation ?

  7. Joel_Eisenstat

    5 May 2018 User since 2016

    Still funky around the function dateWithTimeIntervalSince1970(timeInterval: Float)
    crashes Creo during manipulation , writing to console , etc.
    Deleted associated methods and started over and now seems to be ok.

  8. Joel_Eisenstat

    5 May 2018 User since 2016

    Got it
    dateseconds = Int(date.timeIntervalSince1970);// put day in seconds
    var newdate = dateseconds + 86400 ; // add 1 day
    date = Date(newdate,basedate); // get date via basedate
    Console.write(date); //ok

    var base = "1970-01-01" ;
    basedate = Date( base, "yyyy-dd-MM", "EST") ; // 1970 to Date object
    basedateseconds = basedate.timeIntervalSince1970;

    I think date manipulation should be easier ?
    Regards,
    Joel

  9. marco

    5 May 2018 Administrator User since 2016

    You are right @Joel_Eisenstat, date manipulation should be easier.
    That's the reason why we added the following methods/properties to the new upcoming beta:

    Properties

    var timeIntervalSinceNow: Float The interval between the date object and the current date and time. (read-only)
    
    var timeIntervalSince1970: Float The interval between the date object and 00:00:00 UTC on 1 January 1970. (read-only)
    
    var era: Int Extract era from current date. (read-only)
    
    var year: Int Extract year from current date. (read-only)
    
    var month: Int Extract month from current date. (read-only)
    
    var day: Int Extract day from current date. (read-only)
    
    var hour: Int Extract hour from current date. (read-only)
    
    var minute: Int Extract minute from current date. (read-only)
    
    var second: Int Extract second from current date. (read-only)
    
    var nanosecond: Int Extract nanosecond from current date. (read-only)
    
    var weekday: Int Extract weekday from current date. The weekday units are the numbers 1 through N (where for the Gregorian calendar N=7 and 1 is Sunday). (read-only)
    
    var weekdayOrdinal: Int The weekday ordinal unit describes ordinal position within the month unit of the corresponding weekday unit. For example, in the Gregorian calendar a weekday ordinal unit of 2 for a weekday unit 3 indicates "the second Tuesday in the month". (read-only)
    
    var quarter: Int Extract quarter from current date. (read-only)
    
    var weekOfMonth: Int Extract the original week of a month calendar unit. (read-only)
    
    var weekOfYear: Int Extract the original week of the year calendar unit. (read-only)
    
    var yearForWeekOfYear: Int Extract the ISO Week Date from current date. (read-only)

    Class Methods

    func dateWithTimeIntervalSince1970(timeInterval: Float): Date Creates and returns a Date object set to a given number of seconds from 00:00:00 UTC on 1 January 1970.
    
    func dateWithTimeIntervalSinceReferenceDate(timeInterval: Float): Date Creates and returns a Date object set to a given number of seconds from 00:00:00 UTC on 1 January 2001.
    
    func knownTimeZoneNames(): List Returns an array of strings listing the names of all the time zones known to the system.
    
    func tomorrow(): Date Creates and returns a Date object set to tomorrow.
    
    func yesterday(): Date Creates and returns a Date object set to yesterday.
    
    func dateWithDaysFromNow(reference: Int): Date Creates and returns a Date object set by adding reference days to the current date and time.
    
    func dateWithDaysBeforeNow(reference: Int): Date Creates and returns a Date object set by subtracting reference days to the current date and time.
    
    func dateWithHoursFromNow(reference: Int): Date Creates and returns a Date object set by adding reference hours to the current date and time.
    
    func dateWithHoursBeforeNow(reference: Int): Date Creates and returns a Date object set by subtracting reference hours to the current date and time.
    
    func dateWithMinutesFromNow(reference: Int): Date Creates and returns a Date object set by adding reference minutes to the current date and time.
    
    func dateWithMinutesBeforeNow(reference: Int): Date Creates and returns a Date object set by subtracting reference minutes to the current date and time.

    Initializers

    func Date(timeInterval: Float) Returns a Date object relative to the current date and time by a given number of seconds.
    
    func Date(timeInterval: Float, date: Date) Returns a Date object relative to another given date by a given number of seconds.
    
    func Date(string: String, format: String, timeZone: String) Returns a Date object converted from a textual representations of dates and times.

    Methods

    func isEqualToDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object is exactly equal to a reference date.
    
    func diff(refDate: Date): Float Returns the interval between the receiver and the reference Date parameter. If the receiver is earlier than reference Date, the return value is negative.
    
    func isEqualToDateIgnoringTime(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object is equal to a reference Date ignoring the time value.
    
    func isToday(): Bool Returns a Boolean value that indicates whether a given Date is set to today.
    
    func isTomorrow(): Bool Returns a Boolean value that indicates whether a given Date is set to tomorrow.
    
    func isYesterday(): Bool Returns a Boolean value that indicates whether a given Date is set to yesterday.
    
    func isSameWeekAsDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object has the same week as a reference Date.
    
    func isThisWeek(): Bool Returns a Boolean value that indicates whether a given Date is set to current week.
    
    func isNextWeek(): Bool Returns a Boolean value that indicates whether a given Date is set to next week.
    
    func isLastWeek(): Bool Returns a Boolean value that indicates whether a given Date is set to last week.
    
    func isSameMonthAsDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object has the same month than a reference Date.
    
    func isThisMonth(): Bool Returns a Boolean value that indicates whether a given Date is set to current month.
    
    func isNextMonth(): Bool Returns a Boolean value that indicates whether a given Date is set to next month.
    
    func isLastMonth(): Bool Returns a Boolean value that indicates whether a given Date is set to last month.
    
    func isSameYearAsDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object has the same year as a reference Date.
    
    func isThisYear(): Bool Returns a Boolean value that indicates whether a given Date is set to current year.
    
    func isNextYear(): Bool Returns a Boolean value that indicates whether a given Date is set to next year.
    
    func isLastYear(): Bool Returns a Boolean value that indicates whether a given Date is set to last year.
    
    func isEarlierThanDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object is earlier than a reference Date.
    
    func isLaterThanDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object is later thana reference Date.
    
    func isInFuture(): Bool Returns a Boolean value that indicates whether a given Date is set to sometime in the future.
    
    func isInPast(): Bool Returns a Boolean value that indicates whether a given Date is set to sometime in the past.
    
    func dateByAddingYears(reference: Int): Date Creates and returns a new Date object set by adding reference years to the current date.
    
    func dateBySubtractingYears(reference: Int): Date Creates and returns a new Date object set by subtracting reference years to the current date.
    
    func dateByAddingMonths(reference: Int): Date Creates and returns a new Date object set by adding reference months to the current date.
    
    func dateBySubtractingMonths(reference: Int): Date Creates and returns a new Date object set by subtracting reference months to the current date.
    
    func dateByAddingDays(reference: Int): Date Creates and returns a new Date object set by adding reference days to the current date.
    
    func dateBySubtractingDays(reference: Int): Date Creates and returns a new Date object set by subtracting reference days to the current date.
    
    func dateByAddingHours(reference: Int): Date Creates and returns a new Date object set by adding reference hours to the current date.
    
    func dateBySubtractingHours(reference: Int): Date Creates and returns a new Date object set by subtracting reference hours to the current date.
    
    func dateByAddingMinutes(reference: Int): Date Creates and returns a new Date object set by adding reference minutes to the current date.
    
    func dateBySubtractingMinutes(reference: Int): Date Creates and returns a new Date object set by subtracting reference minutes to the current date.
  10. Joel_Eisenstat

    5 May 2018 User since 2016

    Fantastico !!! It pays to put this module on hold for beta 19
    Are you able to estimate a time frame ?

  11. marco

    5 May 2018 Administrator User since 2016

    @Joel_Eisenstat hold for beta 19 that will be released Tuesday

or Sign Up to reply!