• 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
padding dates etc.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

padding dates etc.


  • Subject: padding dates etc.
  • From: Jean-Christophe Helary <email@hidden>
  • Date: Tue, 13 Mar 2018 14:49:22 +0900

I'm trying to get a yyymmddsssss string to use as a version number and I use
the following code:

set omegat_version to ¬
        ((year of (omegat_creation_date) as string) & ¬
                (JC's myPadding:2 myNumber:(month of (omegat_creation_date) as
integer)) & ¬
                (JC's myPadding:2 myNumber:(day of (omegat_creation_date) as
integer)) & ¬
                (JC's myPadding:5 myNumber:(time of (omegat_creation_date) as
integer))) ¬
                as integer

where the padding routine is:

on myPadding:myPadding myNumber:myNumber
        # adds enough 0 to the left of the number to pad it to the myPadding
value
        # if the number is already long enough, less significant numbers on the
right are removed until the correct length is achieved
        set myLength to (number of items of (myNumber as text))
        if myLength < myPadding then
                set myEndNumber to (text 2 thru -1 of ((10 ^ (myPadding -
myLength) as integer) as text)) & (myNumber as text)
        else if myLength = myPadding then
                set myEndNumber to myNumber
        else if myLength > myPadding then
                set myEndNumber to (text 1 thru myPadding of (myNumber as text))
        end if
        return myEndNumber
end myPadding:myNumber:

and I'm wondering if there is a less convoluted way to accomplish the same
result...

:-)

Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


 _______________________________________________
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:
    • Re: padding dates etc.
      • From: Shane Stanley <email@hidden>
    • Re: padding dates etc.
      • From: Jim Underwood <email@hidden>
  • Prev by Date: Re: Script Editor Bug Tracking Open Windows?
  • Next by Date: Re: padding dates etc.
  • Previous by thread: Re: Script Editor Bug Tracking Open Windows?
  • Next by thread: Re: padding dates etc.
  • Index(es):
    • Date
    • Thread