Revision 2988
Added by sgarg over 18 years ago
test/edu/ucsb/nceas/metacattest/client/MetacatClientTest.java | ||
---|---|---|
650 | 650 |
*/ |
651 | 651 |
private String generateDocid() |
652 | 652 |
{ |
653 |
StringBuffer docid = new StringBuffer(prefix); |
|
654 |
docid.append("."); |
|
655 |
|
|
653 | 656 |
// Create a calendar to get the date formatted properly |
654 | 657 |
String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); |
655 | 658 |
SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); |
... | ... | |
658 | 661 |
Calendar calendar = new GregorianCalendar(pdt); |
659 | 662 |
Date trialTime = new Date(); |
660 | 663 |
calendar.setTime(trialTime); |
661 |
String docid = String.format(prefix +".%1$tY%1$tj%1$tH%1$tM%1$tS", calendar); |
|
662 |
return docid; |
|
664 |
|
|
665 |
int time = 0; |
|
666 |
|
|
667 |
docid.append(calendar.get(Calendar.YEAR)); |
|
668 |
|
|
669 |
time = calendar.get(Calendar.DAY_OF_YEAR); |
|
670 |
if(time < 10){ |
|
671 |
docid.append("0"); |
|
672 |
docid.append("0"); |
|
673 |
docid.append(time); |
|
674 |
} else if(time < 100) { |
|
675 |
docid.append("0"); |
|
676 |
docid.append(time); |
|
677 |
} else { |
|
678 |
docid.append(time); |
|
679 |
} |
|
680 |
|
|
681 |
time = calendar.get(Calendar.HOUR_OF_DAY); |
|
682 |
if(time < 10){ |
|
683 |
docid.append("0"); |
|
684 |
docid.append(time); |
|
685 |
} else { |
|
686 |
docid.append(time); |
|
687 |
} |
|
688 |
|
|
689 |
time = calendar.get(Calendar.MINUTE); |
|
690 |
if(time < 10){ |
|
691 |
docid.append("0"); |
|
692 |
docid.append(time); |
|
693 |
} else { |
|
694 |
docid.append(time); |
|
695 |
} |
|
696 |
|
|
697 |
time = calendar.get(Calendar.SECOND); |
|
698 |
if(time < 10){ |
|
699 |
docid.append("0"); |
|
700 |
docid.append(time); |
|
701 |
} else { |
|
702 |
docid.append(time); |
|
703 |
} |
|
704 |
|
|
705 |
return docid.toString(); |
|
663 | 706 |
} |
664 | 707 |
} |
Also available in: Unified diff
fix to the earlier commit. the code was dependent on 1.5. this one isnt