コード例 #1
0
ファイル: info.py プロジェクト: chrisgrande/munki
def subtract_tzoffset_from_date(the_date):
    """Input: NSDate object
    Output: NSDate object with same date and time as the UTC.
    In Los Angeles (PDT), '2011-06-20T12:00:00Z' becomes
    '2011-06-20 12:00:00 -0700'.
    In New York (EDT), it becomes '2011-06-20 12:00:00 -0400'.
    This allows a pkginfo item to reference a time in UTC that
    gets translated to the same relative local time.
    A force_install_after_date for '2011-06-20T12:00:00Z' will happen
    after 2011-06-20 12:00:00 local time.
    """
    # find our time zone offset in seconds
    timezone = NSTimeZone.defaultTimeZone()
    seconds_offset = timezone.secondsFromGMTForDate_(the_date)
    # return new NSDate minus local_offset
    return NSDate.alloc(
        ).initWithTimeInterval_sinceDate_(-seconds_offset, the_date)
コード例 #2
0
ファイル: info.py プロジェクト: chrisgrande/munki
def add_tzoffset_to_date(the_date):
    """Input: NSDate object
    Output: NSDate object with timezone difference added
    to the date. This allows conditional_item conditions to
    be written like so:

    <Key>condition</key>
    <string>date > CAST("2012-12-17T16:00:00Z", "NSDate")</string>

    with the intent being that the comparision is against local time.

    """
    # find our time zone offset in seconds
    timezone = NSTimeZone.defaultTimeZone()
    seconds_offset = timezone.secondsFromGMTForDate_(the_date)
    # return new NSDate minus local_offset
    return NSDate.alloc(
        ).initWithTimeInterval_sinceDate_(seconds_offset, the_date)
コード例 #3
0
def add_tzoffset_to_date(the_date):
    """Input: NSDate object
    Output: NSDate object with timezone difference added
    to the date. This allows conditional_item conditions to
    be written like so:

    <Key>condition</key>
    <string>date > CAST("2012-12-17T16:00:00Z", "NSDate")</string>

    with the intent being that the comparision is against local time.

    """
    # find our time zone offset in seconds
    timezone = NSTimeZone.defaultTimeZone()
    seconds_offset = timezone.secondsFromGMTForDate_(the_date)
    # return new NSDate minus local_offset
    return NSDate.alloc().initWithTimeInterval_sinceDate_(
        seconds_offset, the_date)
コード例 #4
0
ファイル: yo_scheduler.py プロジェクト: swibrow/yo
def schedule_notification(args):
    """Schedule a notification to be delivered to users"""
    # Get the arguments from the system-level preferences (i.e.
    # /Library/Preferences/com.sheagcraig.yo.plist). This precludes us
    # from using the _slightly_ shorter CFPreferencesCopyAppValue.
    notifications = CFPreferencesCopyValue("Notifications", BUNDLE_ID,
                                           kCFPreferencesAnyUser,
                                           kCFPreferencesAnyHost)
    # We get an immutable NSCFDictionary back from CFPreferences, so
    # copy it to a mutable python dict.
    notifications = dict(notifications) if notifications else {}

    # Convert args to string representation of a python list for later
    # reconversion back to python.
    notifications[repr(args)] = NSDate.alloc().init()

    CFPreferencesSetValue("Notifications", notifications, BUNDLE_ID,
                          kCFPreferencesAnyUser, kCFPreferencesAnyHost)

    # Use the simpler `AppSynchroniize`; it seems to flush all changes,
    # despite having to use the primitive methods above.
    CFPreferencesAppSynchronize(BUNDLE_ID)