Libby Hemphill research and posts on social media, collaboration, and related technologies

14Mar/096

JavaScript date checking

Sometimes we ask users to enter a date range. I wrote some code today to check whether the date a user entered was (1) after today and (2) before some other date she entered. In my situation, I was building a flight search form and wanted to check that the user-entered departure date was before the user-entered return date and that the user wasn't trying to depart in the past. To do this, I needed to turn the user's input into a JavaScript Date and then compare that Date to Today's date. I found a lot of similar code online, but none of it work quite right.

I have a form with text box inputs for dateDepart and dateReturn. This code takes those inputs, turns them in JavaScript dates, compares them to each other and to today, and returns alerts or submits the form, depending on how the comparisons shake out.

Here's my code:

// check to make sure Return date is after Departure date, and both are after today
if ( (the_form.dateDepart.value !="") && (the_form.dateReturn.value !="") )
{
	var strFromDate = the_form.dateDepart.value;
	var dayPartFromDate = parseInt(strFromDate.substring(3,5),10);
	var monPartFromDate = parseInt(strFromDate.substring(0,2),10);
	var yearPartFromDate = parseInt(strFromDate.substring(6,10),10);
	var dtDepart = new Date(yearPartFromDate, monPartFromDate-1, dayPartFromDate);

	var strToDate = the_form.dateReturn.value;
	var dayPartToDate = parseInt(strToDate.substring(3,5),10);
	var monPartToDate = parseInt(strToDate.substring(0,2),10);
	var yearPartToDate = parseInt(strToDate.substring(6,10),10);
	var dtReturn = new Date(yearPartToDate, monPartToDate-1, dayPartToDate);
	var now = new Date();
	var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());	

	if(dtDepart > dtReturn)
	{
		alert('Departure date must be before return date. Please fix and resubmit.');
		return false;
	}
	else if (dtDepart < today)
	{
		alert('Departure date must be after today. Please fix and resubmit.');
		return false;
	}
	else
	{
		the_form.submit();
	}
}

Turn User Input into a JavaScript Date
To turn the user's input into a Date, I needed to parse the input and then pass the pieces to the Date() function.

The JavaScript substr function syntax I used corresponds to dateToChange.substring(start,finish). My users are mostly in the U.S., and they enter dates in the form MM/DD/YYYY, e.g., 03/14/2009. JavaScript starts counting at 0, so the substr functions above grab "14" for the day, "03" for the month, and "2009" for the year and then pass those substrings to the Date()function to be converted in a Date JavaScript understands.

getFullYear(); returns a four-digit year such as "2009" that makes it easy to compare to the default version of today's date that
var now = new Date();
var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());

gives.

Why monPartToDate-1? Remember, JavaScript starts counting at 0, so January is month 0, and December is month 11. That means I need to subtract 1 from what my user entered to get the right month for JavaScript.

Compare Dates
I needed to compare the two dates the user entered to make sure she had departure first, then return. Once I have converted both her inputs to JavaScript dates, the comparison uses a simple "greater than" operator: dtDepart &gt; dtReturn

Calling the Date-checking Function
You'll notice my code doesn't include a function declaration; that's because this date-checking procedure is part of a larger function to validate my form. You could wrap this code in a function declaration such as
function checkDates(the_form){}

In order to call the code when the user submits the form, I like to use something like

<input id="search" onclick="checkDates(this.form);" type="button" value="Submit Form" />

in the HTML.

17Feb/094

iPhone’s glass is broken. What to do?

UPDATE: I got my iPhone fixed by Mission: Repair and am very happy. See my review post.

Yes, I dropped my iPhone today. Yes, that drop, from less than 3 feet, cracked the glass. Yes, I wanted to cry.

Now what do I do? I went to the Genuis Bar at the Briarwood Apple Store right away, and they told me, as I expected, that they could get me a replacement iPhone for $299. You read that right. They didn't offer to repair my phone; they offered to replace it, maybe with a refurbished one, for the same price I originally paid. I asked if there were repair options, and they said not with them. Paying $299 would also get me a new warranty that lasts until August. As is, my warranty is void since the break was accidental. So,

Option 1: Pay Apple $299 and hope they give me a new one instead of a refurb.

I looked around online for other options. Since my warranty's void anyway, I'm not that concerned about a warranty-saving repair. This guy's site - http://3gcrackedglass.com - is pretty much right on about repair options and prices. The two sites I see mentioned most often when I search for repair info are iResQ and Mission:Repair. iResQ is supposedly an Apple Authorized repair provider, but they have some service and PR issues. Apparently that particular problem was resolved. So,

Option 2: Pay iResQ $129 or Mission:Repair $137 to fix it and ship it back overnight

Of course, I could always just live with the cracked screen, making

Option 3: Put the iPhone back in its case, and live with a cracked screen.

I had an InCase skin on my iPhone for awhile. I took it off because it made it really hard to get the phone in and out of my pocket. It also made it bulky. Oh, and, I was a little irked at having to pay $30 for an accessory to make the iPhone marginally more durable. The other $300 cell phones I've owned didn't need cases to be durable. If I'd had my case on today, my screen may not have cracked. I take responsibility for dropping my phone. I still think it's ludicrous to offer only replacement and not repair. I get that Apple makes a load more money doing it that way, but the process is infuriating and wasteful.

Mini rant about Apple

In the last 2.5 years, I've spent about $4100 on Apple hardware - 2 laptops and an iPhone. My MacBook required two new logic boards, three new keyboards, and a new hard drive. My MacBook Pro requires new fans and probably a new logic board. None of those 8 repairs were my fault. My laptops have spent about 2 weeks at Apple service facilities and require another 5-7 day stay to fix the fans. My iPhone has worked fine since I bought it in August, but the fact that it cannot withstand a rather routine and expected fall made me furious today. I've been patient with my other Apple hardware. I've sent my computer in for repair and tried to work on my dissertation using backup data and backup computers. I've been through the ringer with their hardware, and I'm exasperated. I don't want to be a whiner, and I don't want to minimize my role in breaking my iPhone. But, I don't think I can recommend Apple products anymore. They either come broken like my MacBook, break almost immediately like my MacBook Pro, or require unreasonable gentleness like my iPhone. At twice the price of comparable laptops and cell phones from competitors, I expected more. Sigh. I'm no longer convinced that the software advantages Apple platforms provide make them worth the hassle or cost. I'm left thinking maybe I should have stuck with my Dell and my BlackBerry.

Oh, and the total cost of ownership for Apple products are even higher. Every laptop needs $30 adapters to work with external monitors, and apparently every iPhone needs a $30 case to protect it. Yes, needs. So add 1.4% to your laptop bill for each adapter you need, and add 15-20% for a case for each iPhone. And those are just the beginning.

4Jan/090

Why not Time Machine?

A couple of commenters asked why I use the ChronoSync + SuperDuper! combination instead of just Time Machine. The main reason? Time Machine uses too many resources. It's also slow. For awhile I avoided it because I wasn't sure how to make a bootable backup, but Mac OS X hints has instructions.

I don't always have my external hard drives plugged in since I'm rocking a laptop and am pretty mobile. Time Machine complained every hour, on the hour, that it couldn't find the drive it wanted for long enough to annoy me. Eventually it stops complaining about not being able to find the drive it wants.

Even if you leave the drive plugged in while working at your base location, for me it's my home office, Time Machine sucks up resources to do those intermittent backups. Even when I'm working on my dissertation, my data is not so mission-critical that it needs to be backed up every hour. Mac OS X Hints has a solution for changing the backup interval too.

ChronoSync can do in 39 minutes what it takes Time Machine over an hour to do. SuperDuper! beats the initial setup by about 20 minutes. So, the ChronoSync + SuperDuper! setup saves me resources, time, and headache.

One more thing - I have an Airport Extreme router, and I hang a hard drive off it via USB also. That drive is open to anyone on our home network. Apple's not kidding when they say Time Machine does not support network backups except to Time Capsule. When I tried using Time Machine to backup to that USB drive off the Airport Extreme, it would run my CPU up to about 80% and break many of my network connections. You may have better luck there. I didn't troubleshoot or try to fix it; I just gave up.

I ordered a rocstor ROCRAID from mwave last week, and that should be here on Tuesday. I'll try out RAID storage for my stuff and see how that goes. It has FireWire connections too, and I'm interested to see how much faster that can really be. I really don't want to have to give my laptop to Apple for a week. They won't let me keep the hard drive and send it in with a different one, and they won't give me a loaner. So I paid $2500 to have a laptop 98% of the time. Would I get it 100% of the time if I'd spent $3000? Sorry for the minirant, but having to get my MacBook Pro's fan fixed is what prompted this latest round of backup chatter.

3Jan/090

Tweeteorology.com

tweeteorology.com just launched. It's the first project from my new company - Magical Pork. Tweeteorology shows tweets (posts to Twitter) about the weather. You can limit the search by location. I am actively developing Tweeteorology and welcome your suggestions.

Thanks, Molly, for the tweeteorology idea!

2Jan/097

Backing up My Mac

My posts about cloning at Boot Camp drive and swapping hard drives in a MacBook are the most popular, according to Google Analytics. Today's special treat, therefore, is a quick overview of an easy, successful, inexpensive backup routine for all your Mac owners.

Our goals:

  1. Create a bootable backup of a Mac,
  2. Update that backup occasionally, updating only the stuff that's changed rather than copying the whole drive again, and
  3. Not spending much money.

What you'll need (besides a working Mac):

  • SuperDuper! - the free version
  • ChronoSync - latest version; $30 until v4.0 comes out, then price goes up to $40. v4.0 is already late, so the price could change any day.
  • An external hard drive* - something bigger than your internal drive. I use a 3:1 ratio of external:internal storage

Steps to make bootable and differential backups:

  1. Make a bootable backup using the free version of SuperDuper! (see the SuperDuper! user's guide for compete instructions; it comes with your download)

    SuperDuper main screen

  2. Schedule syncing with ChronoSync; tell ChronoSync you're syncing two Macs (see the ChronoSync help menu for complete instructions)

    ChronoSync main page
    You'll see that "cannot locate target" message in the ChronoSynce window if you forget to plug in the external drive.

  3. Remember to leave your computer running when your backups are scheduled. I set a reminder in Google Calendar. It reminds me every week to leave my laptop running overnight so it'll backup.

Making the bootable backup with SuperDuper! took just over 3 hours on my MacBook Pro with 192GB of files. ChronoSync usually takes about 2 hours to sync - only about 45 minutes if I exclude my VMWare virtual machine from the backup. My virtual machine is over 40GB now, and since it always appears as "changed" in ChronoSync's analysis, it gets backed up every time my sync task runs.

I'm experimenting with backing up over a network using rsync and scp. When I get that worked out, I'll post the instructions here. I'm obsessed with backup now that my dissertation is coming along. I don't want anything to happen to those files (or my pictures), so I have them (both) in quadruplicate and on 2 continents. I suggest you set up something similar for the files that are really important to you.

*Notes on shopping for hard drives
Prices on external hard drives are dropping pretty fast, and you should be able to get a good deal. You can build your own external drive by buying an enclosure and an internal drive, or you can buy a ready-made external drive. Sometimes internal drives go on such a huge sale that building your own is cheaper, but ready-made externals are now competitively priced. Building your own has advantages like making the drive swappable and maybe helping you get a FireWire port for less money, and it's not hard. If you find a great deal on an enclosure and internal drive, go for it!

Where are these deals? I recommend checking the forums at Fat Wallet first to see if any site is having a big sale. I often buy drives from NewEgg because they have great prices, really fast shipping, and reasonable return policies. I use only Western Digital and Seagate drives. PC Mag has a good review site for hard drives.

24Mar/080

New (to me) and not Useful: emacs therapist

Lifehacker comes through again with something fun. This time, it's a software Easter Egg - emacs Therapist! To use the emacs Therapist (Mac OS X only), open Terminal, type emacs, hit return, hit Escape, then type xdoctor. You get Eliza. Ha! That can kill some time.

If you're looking for other ways to kill time, may I recommend shopping for t-shirts? I found Palmer Cash recently, and it makes me pretty happy.

Filed under: Links, OS X, adSense No Comments
28Jan/0811

Swapping MacBook hard drives, including Boot Camp partition

Sigh. I use Parallels and Boot Camp because I like having options. Unfortunately, wanting options means that my life is quite complicated. Today's problem: swap out the failing hard drive in my MacBook for a new one without losing any of my Mac OS or Windows XP data. Well, it's actually this month's problem, but whatever. Judging by the amount of search results I get when looking for help online, lots of people want to move their Boot Camp partition to a new drive or to back it up. This should solve both those problems. Here's my setup:

  • MacBook 2.0 GHz Core Duo
  • 160GB internal drive (brand new; Leopard cloned my Mac OS disk partition from the old drive to the new one)
    • 145GB Mac OS X partition (running fine)
    • 15GB Boot Camp partition (formatted FAT32 by Boot Camp Assistant; empty)
  • 160GB external drive (used to be internal, now in a case and attached via USB)
    • 130GB Mac OS X partition
    • 30GB Boot Camp partition (formatted FAT32 by BCA; runs fine)
  • Parallels 3.0
  • Winclone
  • Windows XP SP2

And here's what I did:

Convert the external drive's Windows partition from FAT32 to NTFS:

  1. On the external Windows drive, go to Start - Run - and type cmd to get the command line
  2. At the prompt type convert c: /fs:ntfs where "c:" is the drive you want to convert to NTFS
  3. Answer "No" to the first question - forcefully unmount the drive
  4. Answer "Yes" to the second question - convert on restart
  5. Restart your drive

I did all of that using Parallels so I could work on other stuff at the same time. When you restart, diskcheck will run a few times to convert the drive, and then it will restart in NTFS.

Once you've successfully converted your Windows drive to NTFS, you can clone it using Winclone. Winclone's site has good instructions, but here they are just in case:

  1. Make an image of the Windows partition you want to clone
  2. Store that image on your internal Mac OS partition (where you have Winclone installed)
  3. Restore the Winclone image to the empty Boot Camp partition

Questions
1. Why convert from FAT32 to NTFS?
I tried a number of ways of migrating my FAT32 drive (dd, Acronis True Image), and they all failed. Winclone works for NTFS drives and is a snap.

2. Won't converting from FAT32 to NTFS mean I can't write from my Mac to my Boot Camp drive or cause other problems?
Nope. The conversion happens without harming your data, so that's not a problem. As far as writing from Mac OS to NTFS, you can do so through Parallels. That's good enough for me, and NTFS adds protections and features that FAT32 can't offer. See Microsoft's site for more information about FAT32 vs. NTFS

3. How long does this take?
About two and a half hours from start to finish (18GB partition)

4. Winclone warned me about something happening to my partition; what should I do?
Winclone's just making sure you know that if you disconnect any of the partitions it's using while it's working, bad things will happen. As long as you leave everything connected while Winclone runs, you'll be fine.

5. Winclone thinks my Windows drive is FAT32, but I converted it to NTFS. What do I do?
Restart Winclone or click "Refresh" next to the Source drop down in the Backup tab. It should recognize your drive as NTFS then.

6. Will this work with Vista?
I have no idea. I bet, but I don't use Vista so can't be sure.

7. Where can I get a good deal on an external hard drive?
Try Amazon!

25Jan/080

Ink well?

So I borrowed my friend's Uacom padh do a little teshmg. I'm Using A to write this post.Sv far , It's not doing SO weU.Some Of you owtthere May want toArgue that this lS a PEBKAC issue,but I know better.What I dm'd know Is how toInsert spaces .Ov hew to preventthem from be,. ngInsert ed.there's a settingthat asked about tWspa e1ng M my handwriting, and£ shouldplay with that.I should also Work on picking up my pen betweenletters H see Ms.OK .Eng ouchvvtt` ng In Ink .

So there you go, my first blog post written using Inkwell, Apple's built-in handwriting technology (strangely, they have no page about it that I can find). Thank you, Cory, for loaning me your Wacom pad. I can see how I might grow to love such a thing but think that maybe my interview subjects will not. Of course, when I'm interviewing people who like new technologies, they may get excited about using the pad to draw and sketch for me, and that would mean more data. More data is my favorite kind. Well, maybe not my favorite, but you know what I mean.

Here's a translation of what that paragraph should have said:
So I borrowed my friend's Wacom pad to do a little testing. I'm using it to write this post. So far, it's not doing so well. Some of you may want to argue that this is a PEBKAC issue, but I know better. What I don't know is how to insert spaces or how to prevent them from being inserted. There's a setting that asked about the spacing in my handwriting, and I should play with that. I should also work on picking up my pen between letters. Ok. Enough writing in Ink.

I guess the lesson here is that, on first use, Ink and Wacom work well enough that I can decipher what I wrote but not well enough to capture it all on the first pass. Not bad for a first time, I guess. Oh, and PEBKAC = Problem Exists Between Keyboard And Chair (i.e. user's fault). It's (almost) never the user's fault. Stuff should just work.

24Jan/080

New and Useful: Google Sync for BlackBerry

In December, Google released a new application called Google Sync for BlackBerry that automatically sync's your device calendar with your Google Calendar. For anyone else using the clunky Google Calendar mobile version in their BlackBerry browser, this is quite exciting.

To download, visit http://m.google.com/sync from your BlackBerry browser.

If you'd rather not have another app on your device, but you want an easier way to get to your Google Calendar, try texting GVENT (48368). You'll get an SMS back with your calendar information: "nday" = next day's calendar; "next" = next event; "day" = today's events