I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
  • meeh's avatar
    7615b923
    Adding all new code, removed a lot obsolete code and fixed import paths etc. · 7615b923
    meeh authored
    Mac OS X launcher:
    * UI built on Swift
      * Why?
        * Apple seems to on purpose make it harder to get into Objective-C these days
        * Swift is compiled to native code, but has easiness of Javascript in programming
        * Perfect for the OS X UI, many guides & tutorials as well
    * "Backend" in Objective-C++ / C++14
      * Why?
        * Originally written in Objective-C / C++14 with C++17 backports
        * Only for backend because of the time the development takes
        *
    
    Short summary of features:
    
    * Java
      * It can detect java from:
        * JAVA_HOME environment variable
        * "Internet Plug-Ins" Apple stuff
        * By the /usr/libexec/java_home binary helper
      * It can unpack a new version of I2P
        * Unpacks to ~/Library/I2P
        * Can check currently unpacked version in ~/Library/I2P via i2p.jar's "net.i2p.CoreVersion"
    
      * User Interface (a popover, see https://youtu.be/k8L3lQ5rUq0 for example of this concept)
        * Router control tab view
          * It can start the router
          * It can stop the router
          * It can detect already running router, then avoid fireing up one
          * It can show basic information about the router state & version
        * Log view tab (not yet done)
      * While left-click triggers popover, right-click draws a minimal context menu
    7615b923
    History
    Adding all new code, removed a lot obsolete code and fixed import paths etc.
    meeh authored
    Mac OS X launcher:
    * UI built on Swift
      * Why?
        * Apple seems to on purpose make it harder to get into Objective-C these days
        * Swift is compiled to native code, but has easiness of Javascript in programming
        * Perfect for the OS X UI, many guides & tutorials as well
    * "Backend" in Objective-C++ / C++14
      * Why?
        * Originally written in Objective-C / C++14 with C++17 backports
        * Only for backend because of the time the development takes
        *
    
    Short summary of features:
    
    * Java
      * It can detect java from:
        * JAVA_HOME environment variable
        * "Internet Plug-Ins" Apple stuff
        * By the /usr/libexec/java_home binary helper
      * It can unpack a new version of I2P
        * Unpacks to ~/Library/I2P
        * Can check currently unpacked version in ~/Library/I2P via i2p.jar's "net.i2p.CoreVersion"
    
      * User Interface (a popover, see https://youtu.be/k8L3lQ5rUq0 for example of this concept)
        * Router control tab view
          * It can start the router
          * It can stop the router
          * It can detect already running router, then avoid fireing up one
          * It can show basic information about the router state & version
        * Log view tab (not yet done)
      * While left-click triggers popover, right-click draws a minimal context menu
DateTimeUtils.swift 2.39 KiB
//
//  DateTimeUtils.swift
//  I2PLauncher
//
//  Created by Mikal Villa on 18/09/2018.
//  Copyright © 2018 The I2P Project. All rights reserved.
//

import Foundation

extension Date {
  init(date: NSDate) {
    self.init(timeIntervalSinceReferenceDate: date.timeIntervalSinceReferenceDate)
  }
}

extension NSDate {
  convenience init(date: Date) {
    self.init(timeIntervalSinceReferenceDate: date.timeIntervalSinceReferenceDate)
  }
}

class DateTimeUtils {
  static func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
    let calendar = NSCalendar.current
    let unitFlags: Set<Calendar.Component> = [.minute, .hour, .day, .weekOfYear, .month, .year, .second]
    let now = NSDate()
    let earliest = now.earlierDate(date as Date)
    let latest = (earliest == now as Date) ? date : now
    let components = calendar.dateComponents(unitFlags, from: earliest as Date,  to: latest as Date)
    
    if (components.year! >= 2) {
      return "\(components.year!) years ago"
    } else if (components.year! >= 1){
      if (numericDates){
        return "1 year ago"
      } else {
        return "Last year"
      }
    } else if (components.month! >= 2) {
      return "\(components.month!) months ago"
    } else if (components.month! >= 1){
      if (numericDates){
        return "1 month ago"
      } else {
        return "Last month"
      }
    } else if (components.weekOfYear! >= 2) {
      return "\(components.weekOfYear!) weeks ago"
    } else if (components.weekOfYear! >= 1){
      if (numericDates){
        return "1 week ago"
      } else {
        return "Last week"
      }
    } else if (components.day! >= 2) {
      return "\(components.day!) days ago"
    } else if (components.day! >= 1){
      if (numericDates){
        return "1 day ago"
      } else {
        return "Yesterday"
      }
    } else if (components.hour! >= 2) {
      return "\(components.hour!) hours ago"
    } else if (components.hour! >= 1){
      if (numericDates){
        return "1 hour ago"
      } else {
        return "An hour ago"
      }
    } else if (components.minute! >= 2) {
      return "\(components.minute!) minutes ago"
    } else if (components.minute! >= 1){
      if (numericDates){
        return "1 minute ago"
      } else {
        return "A minute ago"
      }
    } else if (components.second! >= 3) {
      return "\(components.second!) seconds ago"
    } else {
      return "Just now"
    }
    
  }
}