From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17474 invoked by alias); 12 Jun 2013 04:42:14 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17833 Received: (qmail 22681 invoked from network); 12 Jun 2013 04:42:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130611214202.ZM6862@torch.brasslantern.com> Date: Tue, 11 Jun 2013 21:42:02 -0700 In-reply-to: <83808ECC-34C4-42F6-B47B-70F26A6C03BD@gmail.com> Comments: In reply to "TJ Luoma" "best way to convert UTC to local time?" (Jun 11, 5:51pm) References: <83808ECC-34C4-42F6-B47B-70F26A6C03BD@gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: "TJ Luoma" , "Zsh-Users List" Subject: Re: best way to convert UTC to local time? MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Jun 11, 5:51pm, TJ Luoma wrote: } } This is what I have come up with: } } zmodload zsh/datetime } } DATE_ADDED_UTC=$(mdls -raw -name kMDItemDateAdded "$F") } DATE_ADDED_UTC_EPOCH=$(TZ=UTC strftime -r "%Y-%m-%d %H:%M:%S +0000" } "$DATE_ADDED_UTC") } DATE_ADDED_LOCAL=$(strftime "%Y-%m-%d" "$DATE_ADDED_UTC_EPOCH") } } This works, but three separate `strftime` calls seems inefficient. I } mean, it's not like it takes a long time to run or anything, I'm just } wondering if there's a "better" way. I count only two strftime calls? Without writing something like mdls but that returns the field as an epoch timestamp, anything you use including the "date" command Larry suggested is going to do the same sort of parse/convert that you're doing with strftime here, so I'm just going to mention that you can do the strftime calls themselves "better". If you use the -s SCALAR option to strftime, you can skip the command substitution and its inherent fork and I/O: TZ=UTC strftime -r -s DATE_ADDED_UTC_EPOCH "%Y-%m-%d %H:%M:%S +0000" \ "$DATE_ADDED_UTC" strftime -s DATE_ADDED_LOCAL "%Y-%m-%d" "$DATE_ADDED_UTC_EPOCH" You could cut out another step by using mdls -nullMarker to assign a fixed date to files that don't have one, instead of testing "(null)" to skip those files: TZ=UTC strftime -r -s DATE_ADDED_UTC_EPOCH "%Y-%m-%d %H:%M:%S +0000" \ $(mdls -raw -name kMDItemDateAdded \ -nullMarker "2013-06-11 00:00:00 +0000" "$F") Also you could do [[ -f $F && -r $F ]] in a single condition, but that's not going to make much difference unless you're processing a really large number of files.