• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Correcting AGE_INFO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Correcting AGE_INFO


  • Subject: Re: Correcting AGE_INFO
  • From: "Nigel Garvey" <email@hidden>
  • Date: Thu, 4 Feb 2010 13:57:53 +0000

Bert Groeneveld wrote on Thu, 4 Feb 2010 10:43:21 +0100:

>set D to current date
>tell application "Finder"
>	set M to modification date of alias myFile -- myFile was of course
>set to some file earlier in the script
>end tell
>set AGE_INFO to round (D - M) / days rounding up -- is always an integer
>set AGE_INFO to correct_AGE_INFO(AGE_INFO, D, M)
>
>on correct_AGE_INFO(AGE_INFO, D, M)
>	-- what to put here? (as less code as possible, of course)
>end correct_AGE_INFO
>
>Hello,
>I'm breaking my head about finding some "super algorythm" for this:
>I want to correct AGE_INFO, by omitting the days of the weekend
>(saturday and sunday)

The effort below gets each date's "ignoring weekends" offset in days
from a reference Monday in the past, then subtracts one from the other.
If either of the dates occurs during a weekend, it's advanced to the
following Monday.

  set D to current date
  tell application "Finder"
    set M to modification date of alias myFile -- myFile was of course
set to some file earlier in the script
  end tell
  set AGE_INFO to adjusted_age(M, D)

  -- Return the difference in days between two dates, ignoring Saturdays
and Sundays.
  on adjusted_age(fileDate, queryDate)
    script o
      property refMonday : date "Monday 1 January 1000 00:00:00"

      on offsetInDays(theDate)
        set w to theDate's weekday
        if (w is Saturday) then
          set theDate to theDate + 2 * days
        else if (w is Sunday) then
          set theDate to theDate + days
        end if

        tell (theDate - refMonday) to return it div weeks * 5 + it mod
weeks div days
      end offsetInDays
    end script

    tell o to return offsetInDays(queryDate) - offsetInDays(fileDate)
  end adjusted_age


NG

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • New date bug [Re: Correcting AGE_INFO]
      • From: "Nigel Garvey" <email@hidden>
    • Re: Correcting AGE_INFO
      • From: Bert Groeneveld <email@hidden>
  • Prev by Date: Re: set position does not works "as is"
  • Next by Date: Re: Correcting AGE_INFO
  • Previous by thread: Re: Correcting AGE_INFO
  • Next by thread: Re: Correcting AGE_INFO
  • Index(es):
    • Date
    • Thread